我有一种情况,在wait()之前可以调用notify()’.
当我通过向他发送消息通知他时,我正在尝试制作一个模拟器来安排下一个事件.所以我设计了一个wait-> notify-> scedule链
void Broker::pause()
{
boost::unique_lock<: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<:mutex> lock(m_pause_mutex);
{
m_cond_cnn.notify_one();
}
}
这里的问题是:可能存在在调用wait()之前调用notify()的情况.
这种情况有解决方案吗?
谢谢