wait() の前に notify() を「呼び出すことができる」状況があります。
メッセージを送信して彼に「通知」するときに、次のイベントをスケジュールするシミュレーターを作成しようとしています。そこで、wait->notify->scedule チェーンを考案しました
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() が呼び出される場合があることです。
このような状況の解決策はありますか?ありがとうございました