pthread_exit return value
- by Manty
This is surprising for me.
void * thread_func(void *arg)
{
pthread_exit(&ret);
}
int main(void)
{
pthread_t thr;
int *exit_status;
pthread_create(&thr, NULL, thread_func, NULL);
sleep(2);
pthread_join(thr, (void **)&exit_status);
printf("value of exit status - %d\n", *exit_status);
ret = 20;
pthread_join(thr, (void **)&exit_status);
printf("value of exit status - %d\n", *exit_status);
return 0;
}
The output is
value of exit status - 50
value of exit status - 20
I was expecting both the times the exit_status would be the actual exit value(50 in my case) of the thread. Instead it is just returning the value of the global variable which I used for pthread_exit. Is it not a bug?