Commit e68956fa authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

thread example return values

parent 51a51fd7
......@@ -24,7 +24,7 @@ void * task_a(void * ctx)
for(i=0; i < d->count; ++i){
printf("task_a: %d\n",i);
}
return NULL;
return (void*) 17;
}
void * task_b(void * ctx)
......@@ -36,7 +36,7 @@ void * task_b(void * ctx)
for(i=0; i < d->count; ++i){
printf("task_b: %d\n",i);
}
return NULL;
return (void*) 42;
}
......@@ -45,6 +45,10 @@ int main()
struct global_data data = {10};
pthread_t thread_a;
pthread_t thread_b;
#ifdef RETURN_INT
void *ret_a = 0;
void *ret_b = 0;
#endif
if(pthread_create(&thread_a, NULL, task_a, &data)){
......@@ -55,7 +59,13 @@ int main()
printf("Failed to create thread_b\n");
exit(2);
}
#ifdef RETURN_INT
pthread_join(thread_a, &ret_a);
pthread_join(thread_b, &ret_b);
printf("thread_a returned: %d\nthread_b returned: %d\n", (int)(long)ret_a, (int)(long)ret_b);
#else
pthread_join(thread_a, NULL);
pthread_join(thread_b, NULL);
#endif
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment