Signal Before Wait
A hand-rolled join. There is no state variable, only the condition variable.
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t c = PTHREAD_COND_INITIALIZER;
void thr_exit(void) { // child calls this last
pthread_mutex_lock(&m);
pthread_cond_signal(&c);
pthread_mutex_unlock(&m);
}
void thr_join(void) { // parent calls this
pthread_mutex_lock(&m);
pthread_cond_wait(&c, &m);
pthread_mutex_unlock(&m);
}
On a developer laptop this passes every time. On a loaded CI box it hangs about once in fifty runs. What is the schedule that hangs?
Sign in to answer questions and track your progress
Sign In