C++多线程

[Eclipse]多线程程序编译时的问题以及解决方案

2018-11-21  本文已影响22人  庄阿莫

>>One

问题情景

#include <map>
#include <iostream>
#include <string>
#include <thread>

using namespace std;

void do_some_work()
{
    cout << "1" << endl;
}

int main()
{
    std::thread a(do_some_work);
    a.join();

    std::map<int,int> cp;
    cp[1] = 3;
    cp[1] = 4;
    cp.insert(pair<int ,int>(3,5));
    auto aa = cp.at(3);
    cout << aa << endl;

    return 0;
}

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

怎么做

  1. Window > Preference > Build > Settings > Discovery > CDT GCC Built-in Compiler Settings(shared) 中的(command to get compiler specs) 改为
${COMMAND} -E -P -v -dD "${INPUTS}" -std=c++11
  1. 新建工程项目
-Wl,--no-as-needed -pthread
-std=c++11

为什么这么做

上一篇 下一篇

猜你喜欢

热点阅读