#include<stdio.h>
#include<string.h>
#include<pthread.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
pthread_t id1,id2;
struct arg{int a[2];}*p;
void *sum(void *args)
{
struct arg *b=((struct arg*)args);
printf("hello:%d%d",b->a[0],b->a[1]);
}
void *mul(void *args)
{
struct arg *c=((struct arg*)args);
printf("hi:%d%d",c->a[0],c->a[1]);
}
main()
{
int err1,err2;
p->a[0]=2;
p->a[1]=3;
err1=pthread_create(&id1,NULL,&sum,(void*)p);
err2=pthread_create(&id2,NULL,&mul,(void*)p);sleep(5);
}
I am trying to pass data to threads using structure .....but i always gets a segmentation fault error....can anyone tell me what's wrong with my code..
sumormulwithpsetup as you have it (or lack thereof as the case may be), you would likely get the same result (crash in a ball of flames). In short, you forgot (or never learned) how pointers work in C.