线程创建失败

MinGW-w64 Thread Creation Failure

本文关键字:失败 创建 线程      更新时间:2023-10-16

解析:在杂项链接选项中传递"-static" ——或分辨率:下载此mingw版本http://sourceforge.net/projects/mingwbuilds/?source=dlp

我正在使用带有MinGW-w64工具链的Eclipse。我的GCC版本是4.8

我想创建一个由2个线程组成的应用程序。我已经尝试过在我的实际应用中实现这个。因此,它没有工作,我决定做一个新的测试应用程序。

源(main.cpp):

#include <iostream>
#include <thread>
using namespace std;
void test() {
     cout << "works.." << endl;
}
int main() {
    thread t(test);
    t.join();
    return 0;
}   

构建过程:

21:19:51 **** Build of configuration Debug for project Test ****
make all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -std=gnu++11 -O0 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: Test.exe
Invoking: MinGW C++ Linker
g++  -o "Test.exe"  ./main.o   -lpthread -lwinpthread -pthread -lpthread
Finished building target: Test.exe

21:19:53 Build Finished (took 1s.863ms)

当运行时,我得到以下错误:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted

顺便说一句:许多-pthread等命令来自于几次尝试使其工作。我运行的是winvista 32位

如果有人知道如何解决我的问题,我真的很感激。提前感谢!

查看本地win32 std::thread实现,可以添加到任何c++ 11版本的MinGW中:https://github.com/meganz/mingw-std-threads