开发者

CONDITION_VARIABLE in windows; wont compile

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-pasti开发者_JS百科ng 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?


Did you define _WIN32_WINNT and WINVER 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


Check that you have latest Windows headers, and WinBase.h has the following line:

typedef RTL_CONDITION_VARIABLE CONDITION_VARIABLE, *PCONDITION_VARIABLE;

And of course, you have _WIN32_WINNT #defined to at least 0x600.


You mentioned that you're using pthread library for threading. Have you looked into this article about using mutex for windows, when using pthread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜