MinGW和std :: thread [英] MinGW and std::thread

查看:479
本文介绍了MinGW和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 experimental rubenvb

  4. MinGW -w64: stdthread」实验性质rubenvb 4.7

Number 1不起作用,因为GCC 显然只在内部支持 pthread东西。



2号编译器基本上甚至输出 test (见输出的最后一行),但它也会崩溃的错误:

 终止调用没有活动异常

此应用程序已请求运行时以异常方式终止它。
请联系应用程序的支持团队以获取更多信息。
test

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

 后抛出一个'std :: system_error'
的实例what():启用多线程以使用std :: thread:不允许操作

此应用程序请求运行时终止它在不寻常的方式。
请联系应用程序的支持团队以获取更多信息。

Google带给我的当然是 GCC错误跟踪器和一些其他帖子,建议使用 -pthread ,这不帮助在所有。



我也尝试手动链接 winpthread pthread -std = c ++ 11

c $ c>和 -std = gnu ++ 11 ...



并且不知道,如果它是在所有可能得到一个MinGW版本,支持 std :: thread ,但也许我只是忽略一些编译器标志。

解决方案

您忘了加入您的主题:

  t.join(); 


So I've been trying to get the following code to compile and run on Windows by using a MinGW compiler.

#include <iostream>
#include <thread>

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

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

I'm compiling with the following command:

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

Now the problem is the version of MinGW one should use and I've tried about all the versions I know of.

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

Number 1 doesn't work, since GCC apparently only supports pthread stuff internally.

Number 2 does compile and it essentially even outputs test (see the last line of the output), but it also crashes with the error:

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

Number 3 and 4 again do compile, but they don't output test and instead instantly crashes, but with a more descriptive output:

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.

Google brought me of course to the GCC bug tracker and some other posts, that suggested to use -pthread, which doesn't help at all.

I've also tried manually linking against winpthread and pthread, but that doesn't do anything either.

There's also no difference between -std=c++11 and -std=gnu++11...

I'm really lost right now and don't know, if it's at all possible to get a MinGW version, that supports std::thread, but maybe I'm just overlooking some compiler flags. I hope someone out there can help me!

解决方案

You forgot to join your thread:

t.join();

这篇关于MinGW和std :: thread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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