int main()
{
pthread_t thread;
int a = 0;
while(a == 0)
{
accept(...); //accept a new connection (blocking)
pthread_create(&thread, NULL, threaded_function, &a);
}
pthread_join(...);
return 0;
}
My goal is to keep the main thread looping until a thread returns with a
not equal to zero. The problem is that pthread_create
isn't returning a value. I'm guessing this is because the main thread isn't waiting at pthread_join
, but instead is in a loop waiting at accept
. But if I join the threads inside of the loop, the loop won't be running. Is the only way of accomplishing this by creating another thread, and another threaded function just to watch the value of a
?