Consider the following:
pthread_mutex_t m;
pthread_cond_t c;
//a bunch of passenger threads will all be doing this
pthread_mutex_lock(&m); //passengers join the queue for boarding one at a time
pthread_cond_wait(&c, &m); //joined queue, mutex now unlocked allowing other passengers to join queue
//wait for a ride thread to signal the variable (representing the queue), allowing passengers to board one at a time
//
//Do some work in here required for boarding the ride
//
pthread_mutex_unlock(&m); //allow the next passenger to do the work required to board
Can I guarantee that only one passenger will be able to access the "do some work here" part at a time? From my understanding, once the condition variable is signaled, that thread will relock the mutex and proceed on. What happens if after one thread gets signaled and starts doing work, the ride thread signals the cond variable again? Will the second thread wait for the first thread to unlock the mutex, or will both threads now be in the "do some work here" part?