我有一种情况,即在等待()之前可能会调用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()。
针对这种情况是否有解决方案? 谢谢
notify_one()
队列? - Gabriel Staples