问题描述
在安装MinGW-w64工具链时,我选择了Win32线程模型,在阅读后,它提供比POSIX对应的更好的性能。我没有资格自己对此声明进行基准化,但。
I have opted for the Win32 threading model when installing the MinGW-w64 toolchain, after reading that it provides better performance than the POSIX counterpart. I am not qualified for benchmarking this claim myself, but here's a source for it.
起初,我认为这个选项只会影响GCC运行时的内部工作,而不会阻止我在我的代码中使用C ++ 11线程,基于和由其他用户 rubenvb 。
然而,似乎不是这样。 $ std :: thread 支持在此MinGW-w64安装中似乎不存在。
At first I thought this option would only affect the inner workings of the GCC runtime, while not preventing me from using C++11 threads in my code, based on this answer and this comment by fellow user rubenvb.
However, this doesn't seem to be the case. std::thread support appears to be non-existent in this MinGW-w64 installation.
命令行中除了 -std = c ++ 11 之外没有其他选项的 g ++ 。
I am invoking g++ from the command line with no options other than -std=c++11.
此时,我不确定是否:
- rubenvb 是错误的,在POSIX线程模型下安装MinGW-w64以编译依赖于C ++ 11 线程库的代码;或
- 我完全误解了所有,或;
- std :: thread 实际上支持我的方案,它只是不直观。
- rubenvb was wrong, and it's actually necessary to install MinGW-w64 under the POSIX threading model in order to compile my code which depends on the C++11 thread library, or;
- I completely misunderstood it all, or;
- std::thread is actually supported in my scenario, it's just not intuitive.
我强调标题中的开箱即用部分。有一个名为的库,如。
I reinforce the "out of the box" part in the title. There exists a library called mingw-std-threads, as presented in this answer. However, as a third-party option, it is not relevant to this question.
因此,截至今天(2016年5月),MinGW-w64 nativelly支持<$
So, as of today (May 2016), does MinGW-w64 nativelly support std::thread depending code, when installed with the Win32 internal threading model?
推荐答案
c $ c> std :: thread p>要使用MinGW-w64与Win32本机线程,您还必须安装 headers。
To use the MinGW-w64 with Win32 native threads you must also install the mingw-std-threads headers.
正如该页面所述,这是因为MinGW-w64是GCC的端口,但GCC不包括任何本机线程支持。相反,GCC安装通常通过gthreads或pthreads作为glibc的一部分来实现线程。 MinGW-w64不包括glibc的端口。 (而是使用MSVC运行时的组合,加上它自己的代码来填补空洞)。
As described on that page, this is because MinGW-w64 is a port of GCC, but GCC does not include any native thread support. Instead GCC installations typically implement threading via either gthreads or pthreads as a part of glibc. MinGW-w64 does not include a port of glibc. (Instead it uses a combination of the MSVC runtime, plus its own code to fill in holes).
也如在那页上所描述的,最新版本的MinGW-w64做包括pthreads的Win32端口,这解释了为什么你可以通过从MinGW-w64安装程序中选择pthread模型,线程工作开箱即用。
Also as described on that page, recent versions of MinGW-w64 do include a Win32 port of pthreads, which explains why you can have threads work "out of the box" by selecting the "pthread" model from the MinGW-w64 installer.
这篇关于当使用Win32线程模型时,MinGW-w64是否支持std :: thread开箱即用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!