Below is the program for which I am expecting the program to go into a deadlock because pthread_join() is a blocking wait on a thread (it is waiting to terminate).
But I see that pthread_join() does not block and returns with failure (35 = EDEADLK)
Can you help me understand why pthread_join() unblocks? Because the main thread is yet to terminate and probably this should be a deadlock?
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int
main(int argc, char *argv[])
{
void *res;
int s;
printf("Message from main()\n");
s = pthread_join(pthread_self(), &res);
if (s != 0)
printf("pthread_join(): %d",s);
printf("Thread returned %d\n", (int) res);
exit(0);
}
Here is the output:
Message from main()
pthread_join(): 35
Thread returned 134514009