This is my struct:
struct example {
int c=0;
char buf[10];
}
I have a struct of this type allocated in main()
...
struct example *ex=malloc(sizeof(*ex));
...
and passed to a thread by
...
pthread_create(&id[i], NULL, t_func, ex);
...
pthread_create is called into a child of main.
t_func is:
void *t_func(void* args) {
struct example *extmp = args;
....
How can I create a local struct example in every thread and copy into it the struct and the values of args? I need it such that if I modify a field of the local struct, that will not be seen in other threads. I’ve seen other similar questions, but I haven’t found my answer…
In C you can assign objects of structure type: