CONDITION_VARIABLE在窗口中;不会编译 [英] CONDITION_VARIABLE in windows; wont compile

查看:293
本文介绍了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 ,它不会编译。我正在使用GCC。



关于如何编译这个的任何想法?或任何其他方法,不涉及condition_variables?

解决方案

您是否定义了 _WIN32_WINNT WINVER 之前 #include< windows.h>



这是必需的,以包含仅在Windows的更高版本中添加的事物的定义。对于条件变量,您需要将这些条件变量设置为至少 0x0600 ,因为条件变量在V6中是新的(即Vista / 2008)。



请参阅 http://msdn.microsoft .com / en-us / library / aa383745%28VS.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?

解决方案

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

这篇关于CONDITION_VARIABLE在窗口中;不会编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆