I have a multithreaded program and in the code below, when the value of y becomes less than 0, I need all the threads to stop running.
Here’s the source code –
else if(y<0)
{
flag=1;
printf("Exit the program\n");
pthread_exit((void *)55);
printf("sdjfajdflsdj");
// return NULL;
}
What is happening is that the program is printing the line – Exit the program, but gets stuck over there. It does not go to the line printf(“sdjfajdflsdj”); and neither does it exit the code.
Can someone please help ?
Thanks
pthread_exitexits the current thread, not others. I believeexitshould exit all threads.