【发布时间】:2013-07-10 05:18:19
【问题描述】:
我有一种情况,即可以在 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() 的情况。
这种情况有解决办法吗? 谢谢
【问题讨论】:
标签: c++ boost synchronization condition-variable ns-3