c - Stuck on a thread issue -


so have

void* tf(void* p); 

which dont totally understand. think is, function pointer void pointer parameter. using make thread this:

pthread_create( &thread_id[i], null, tf, null ); 

what need expliation of tf , how pass parameter it.

i have function defined as

void* tf(void* p)  {     //i use p here dont know how.  } 

this function outside main , needs few other parameters set inside main. have tried making tf(int i) segment fault. know doing wrong , need figuring out.

thanks in mater.

jason

pthread_create( &thread_id[i], null, tf, null ); //                                      ^^^^^ //                       have put here pointer (address) data 

and can data p pointer thread function

example

typedef struct test {    int a,b; } test;  int main()  {    struct test t = {0};    pthread_create( &thread_id[i], null, tf, &t );    pthread_join(thread_id[i], null); // waiting thread finish    printf("%d  %d\n",t.a, t.b); }  void* tf(void* p)  {     struct test *t =  (struct test *) p;     t->a = 5;     t->b = 4; } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -