gpt4 book ai didi

c++ - Windows 事件的等效 boost

转载 作者:可可西里 更新时间:2023-11-01 13:29:03 26 4
gpt4 key购买 nike

在 Windows C++ 中我可以创建一个事件句柄

处理 h = CreateEvent(...)

然后我可以设置和重置该事件

SetEvent(...) 和 ResetEvent(...)

最后,我可以使用命令 OpenEvent(...) 来打开事件

事件是否有等效的 boost ?

最佳答案

我认为您需要使用 boost::mutexboost::unique_lockboost::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();
// }



}

关于c++ - Windows 事件的等效 boost ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5598890/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com