Why do you need a while loop while waiting for a condition variable

后端 未结 3 1648
囚心锁ツ
囚心锁ツ 2020-12-13 02:37

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\'         


        
3条回答
  •  孤街浪徒
    2020-12-13 03:34

    For performance reasons, the POSIX API allows the OS to wake up your thread even if the condition has not been fulfilled (that's called a spurious wakeup).

提交回复
热议问题