c语言notify方法,c – 如果在wait()之前调用notify()怎么办?

我有一种情况,在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()的情况.

这种情况有解决方案吗?

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值