c++ - 在多线程应用程序中等待变量的最佳方法是什么

标签 c++ c windows winapi resources

我想为多线程程序做类似下面的事情:

// wait for variable to become true but don't hog resources  
// then re-sync queues  

something like this一个好的解决方案?

while (!ready) {
    Thread.Sleep(250); // pause for 1/4 second;
};

最佳答案

不,这不是一个好的解决方案。首先它可能睡得太久。其次,线程很容易进入同步状态。以下是有关正确同步技术的 MSDN 文章的几个链接:

关于c++ - 在多线程应用程序中等待变量的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2060200/

相关文章:

c++ - std::shared_ptr 中的错误?

C : Deleting only one node from a doubly linked list

C99, "Despite the name, a non-directive is a preprocessing directive."

windows - 批处理文件脚本

php - 我对类名的选择受到 Windows XP 最大路径长度问题和 SVN/域驱动设计的阻碍——任何解决方案

c# - 将 C++ 代码导出为 DLL 并使用 C# 导入?

c++ - 使用 STL 函数快速填充 vector 、映射和设置

c++ - 为什么下面的代码会崩溃?

c++ - 将 vector<wstring> 与 Boost.Pool 分配器一起使用

c - 僵尸进程即使线程仍在运行