我有一种情况,在 wait() 之前可以调用 notify()。
当我通过向他发送消息“通知”他时,我正在尝试制作一个模拟器来安排下一个事件。所以我设计了一个等待->通知->调度链
void Broker::pause()
{
boost::unique_lock<boost::mutex> lock(m_pause_mutex);
{
std::cout << "pausing the simulation" << std::endl;
m_cond_cnn.wait(lock);
std::cout << "Simulation UNpaused" << std::endl;
// the following line causes the current function to be called at
// a later time, and a notify() can happen before the current function
// is called again
Simulator::Schedule(MilliSeconds(xxx), &Broker::pause, this);
}
}
void Broker::messageReceiveCallback(std::string message) {
boost::unique_lock<boost::mutex> lock(m_pause_mutex);
{
m_cond_cnn.notify_one();
}
}
这里的问题是:可能存在在调用其 wait() 之前调用 notify() 的情况。
这种情况有解决办法吗?谢谢你