Public/tip & tech

pthread_create 다중인자 전달

quantapia 2009. 9. 10. 14:57

typedef struct tTHREAD
{
   int a;
   int b;
}THREAD;

 void *thread_func(void* p)
 {
    THREAD* pp = (THREAD*)p;
    int k = pp->a;
    int j = pp->b;
    printf("k = %d, j = %d\n", k, j);
 
    return (void *)k+1;
 }


int main(int argc, char **argv)
{
   pthread_t th1;
   THREAD st;
   st.a = 1;
   st.b = 2;

   int res;
   int tid;

   tid = pthread_create(&th1, NULL, thread_func, (void *)&st);
   pthread_join(th1, (void **)&res);

   printf("result : %d\n", res);

   return 0;
}