basically, I am trying to understand the real purpose of pthread_exit. As you can see, there are multiple pthread_exit code I have tried. And Following are the result i observe :
- Exit 1: 42
- Exit 2: 42
- Exit 3: thread failed
- Exit 4: error
- Exit 5: 42
- Without a pthread_exit statement: 42
Anyways the value passed(10) to pthread_exit is ignored(Exit 2) and prints the value which we modified via the pointer(42). So what is the real purpose of argument of pthread_exit here? confusing.
int a;
void *myThread(void *result)
{
int a = 5;
*((int*)result) = 42;
pthread_exit(result); // Exit 1
//pthread_exit((void *)10); // Exit 2
//pthread_exit(0); // Exit 3
//pthread_exit(); // Exit 4
//pthread_exit((void *)&a); // Exit 5
}
int main()
{
pthread_t tid;
void *status = 0;
int result;
pthread_create(&tid, NULL, myThread, &result);
pthread_join(tid, &status);
if (status != 0 ) {
printf("%d\n",result);
} else {
printf("thread failed\n");
}
return 0;
}