繁体   English   中英

MinGW和std :: thread

[英]MinGW and std::thread

所以我一直在尝试使用MinGW编译器在Windows上编译和运行以下代码。

#include <iostream>
#include <thread>

void test()
{
    std::cout << "test" << std::endl;
}

int main()
{
    std::thread t(test);
}

我正在使用以下命令进行编译:

g++ -std=c++11 test.cpp -o test.exe

现在问题是应该使用的MinGW版本,我已经尝试过我所知道的所有版本。

  1. MinGW-builds: thread-win32
  2. MinGW-builds: thread-posix
  3. MinGW-w64: stdthread实验rubenvb
  4. MinGW-w64: stdthread实验rubenvb 4.7

数字1不起作用,因为GCC 显然只在内部支持 pthread。

数字2确实编译,它基本上甚至输出test (参见输出的最后一行),但它也崩溃与错误:

terminate called without an active exception

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
test

3号和4号再次进行编译,但它们不输出test而是立即崩溃,但具有更具描述性的输出:

terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

谷歌当然把我带到GCC错误跟踪器和其他一些建议使用-pthread帖子,这根本-pthread

我也试过手动链接winpthreadpthread ,但这也没有做任何事情。

-std=c++11-std=gnu++11之间也没有区别......

我现在真的迷路了,不知道,如果它有可能得到一个支持std::thread的MinGW版本,但也许我只是忽略了一些编译器标志。 我希望有人可以帮助我!

你忘了加入你的主题:

t.join();

仅供参考,已有std :: thread和sync原语的本机win32实现。 它是一个仅限标头的库,适用于任何符合C ++ 11标准的MinGW版本。 https://github.com/meganz/mingw-std-threads

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM