CONDITION_VARIABLE in windows; do not compile

I am trying to make a Windows version of a program written for Linux in C ++. To make the program thread safe, I use pthread_cond_t and pthread_cond_wait in the Linux version. These functions use mutexes to verify that the waiting thread is indeed waiting.

I found that CONDITION_VARIABLE can do the trick on Windows, however I cannot understand why it is not compiling. I get the error "error:" CONDITION_VARIABLE "does not name type", although all relevant headers are included, as far as I can tell. I tried copying the code to http://msdn.microsoft.com/en-us/library/ms686903%28v=VS.85%29.aspx , which also does not compile. I am using GCC.

Any ideas on how to compile this? or any alternative approaches that do not include variable_conditions?

+6
source share
4 answers

Have you defined _WIN32_WINNT and WINVER before #include <windows.h> ?

This is necessary to include definitions for things added only in later versions of Windows. For condition variables, you need to set them to at least 0x0600 , since the condition variables were new in V6 (i.e. Vista / 2008).

See http://msdn.microsoft.com/en-us/library/aa383745%28VS.85%29.aspx

+4
source

Make sure you have the 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 at least 0x600 .

+2
source

You mentioned that you use the pthread library for streaming. You looked at this article about using a mutex for Windows when using pthread.

0
source

Using pthreads-win32 , which implements the POSIX threading API on Windows, this includes condition variables.

-1
source

Source: https://habr.com/ru/post/893854/


All Articles