Windows 中的 CONDITION_VARIABLE;不会编译
我正在尝试用 C++ 制作为 Linux 编写的程序的 Windows 版本。为了使程序是线程安全的,我在Linux版本中使用了pthread_cond_t
和pthread_cond_wait
。这些函数使用互斥体来帮助确保等待线程实际上正在等待。
我发现 CONDITION_VARIABLE
在 Windows 中可能会起作用,但是我不明白为什么它无法编译。据我所知,即使包含所有相关标头,我也会收到错误“错误:'CONDITION_VARIABLE'未命名类型”。我尝试将代码复制粘贴到 http: //msdn.microsoft.com/en-us/library/ms686903%28v=VS.85%29.aspx ,也不会编译。我正在使用海湾合作委员会。
关于如何编译这个有什么想法吗?或任何不涉及条件变量的替代方法?
I am trying to make a windows-version of a program written for Linux, in C++. For the program to be thread-safe, I use pthread_cond_t
and pthread_cond_wait
in the Linux version. These functions use a mutex to help make sure that the waiting thread is actually waiting.
I found that CONDITION_VARIABLE
may do the trick in Windows, however I can't figure out why it wont compile. I get the error "error: 'CONDITION_VARIABLE' does not name a type" even though all relevant headers are included, as far as I can tell. I tried copy-pasting the code on http://msdn.microsoft.com/en-us/library/ms686903%28v=VS.85%29.aspx , which wont compile either. I am using GCC.
Any ideas on how to compile this? or any alternate approaches, which doesn't involve condition_variables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否在
#include
之前定义了_WIN32_WINNT
和WINVER
?这对于包含仅在更高版本的 Windows 中添加的内容的定义是必要的。对于条件变量,您需要将它们设置为至少
0x0600
,因为条件变量是 V6 中的新增内容(即 Vista/2008)。请参阅 http://msdn.microsoft.com/en-我们/库/aa383745%28VS.85%29.aspx
Did you define
_WIN32_WINNT
andWINVER
before#include <windows.h>
?This is necessary to include definitions for things only added in later versions of Windows. For condition variables you need to set these to at least
0x0600
as condition variables were new in V6 (ie. Vista/2008).See http://msdn.microsoft.com/en-us/library/aa383745%28VS.85%29.aspx
检查您是否拥有最新的 Windows 标头,并且 WinBase.h 具有以下行:
当然,您已将
_WIN32_WINNT
#define 至少设置为0x600
。Check that you have latest Windows headers, and WinBase.h has the following line:
And of course, you have
_WIN32_WINNT
#defined to at least0x600
.您提到您正在使用 pthread 库进行线程处理。在使用 pthread 时,您是否看过这篇文章有关在 Windows 上使用互斥锁的内容。
You mentioned that you're using pthread library for threading. Have you looked into this article about using mutex for windows, when using pthread.