Man pages say this pthread_cond_wait atomically unlocks the mutex (as per pthread_unlock_mutex) and waits for the condition variable cond to be signaled.
But then thread start_function could be entered by any other thread causing two threads to be in the critical block.
void* start_function(){
pthread_mutex_lock(&mutex);
// critical block
pthread_mutex_unlock(&mutex);
}
int main(){
// code to create threads
pthread_cond_wait(&cond, &mutex);
}
So in the above code after it hits pthread_cond_wait it will unlock the mutex ?
pthread_cond_waitexactly to prevent unpredictable results. - Cheatah