在windows c ++中,我可以创建一个事件句柄
句柄h = CreateEvent(...)
然后我可以设置并重置该事件
SetEvent(...)和ResetEvent(...)
最后,我可以使用命令OpenEvent(...)来打开OpenEvents
对事件有什么促进作用吗?
我认为你需要使用boost::mutex,boost::unique_lock,boost::condition_variable并可能bool以模拟活动.
实际上你可能需要WaitForSingleObject等待一个事件.可能是这样的:
void wait_for_user_input()
{
boost::unique_lock<boost::mutex> lock(mut);
while(!data_ready)
{
cond.wait(lock);
}
process_user_input(); // it might be not necessary to hold mutex locked here!!!
// if so just add curly braces like this:
// void wait_for_user_input()
// {
// {
// boost::unique_lock<boost::mutex> lock(mut);
// while(!data_ready) { cond.wait(lock); }
// }
// process_user_input();
// }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8120 次 |
| 最近记录: |