线程A:设置变量m_bPaused,m_pPauseEvent是一个信号量对象,提供wait()和set()接口。线程 A 调用它来暂停:
PausePlay(){
m_bPaused = true; // A1
m_pPauseEvent->Wait(0); //A2 wait for the B thread is enter to the waiting
}
线程 B:
if (m_bPaused)
{
m_pPauseEvent->Set(); //B1
m_pPauseEvent->Wait(0); //B2 0 wait forever
}
并调用线程 A 继续线程 B:
m_bPaused = false; //A3
m_pPauseEvent->Set(); //A4
当我暂停时,我等到B1执行完毕。线程A返回。这里会死锁吗?当我在线程 A 中调用 continue 并运行到 A3 时。同时线程 B 仍然在 B1 和 B2 之间,然后线程 A 完成行 m_pPauseEvent->Set()。线程B永远不会收到A4发送的信号。死锁!这会发生吗?