Say you have this code
pthread_mutex_lock(&cam->video_lock); while(cam->status == WAIT_DISPLAY) // <-- Why is this a 'while' and not an 'if'? pthread_cond_wait(&cam->video_cond, &cam->video_lock); pthread_mutex_unlock(&cam->video_lock);
My question is: why do you need a while loop. Would pthread_cond_wait just wait for the signal thread to report cam_video_cond ? Well, I know that you might have a case where cam-> status is not equal to WAIT_DISPAY when pthread_cond_wait is called, but in this case you can just check it using the if condition, and not using , but .
Am I missing something? My understanding of pthread_cond_wait is that it just waits for the infinite if cam_video_cond is not signaled. In addition, it unlocks the cam_video_lock mutex when called, but when the condition is signaled, it blocks cam_video_lock before returning. I'm right?
c linux pthreads signals
Metallicpriest
source share