在使用条件变量的时候,一定要放在一个循环里,这是为什么呢?因为spurious wake-ups
什么是spurious wake-ups?
- Because of some complications in making the condition wake-up completely predictable on multiprocessor systems, spurious wake-ups can occur. That means a thread is awaken even if nobody signaled the condition variable. Therefore it is necessary to check if the condition is still true after the thread has awaken. And since spurious wake-ups can occur multiple times, that check must be done in a loop.
std::condition_variable cv;
while(!g_bSignal)
{
cv.wait(lock);
}