在用g++ 4.8.2编译C++11的线程代码后,运行时遇到了如下报错:

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

我们先看一下代码:

 #include <boost/atomic.hpp>
#include <thread>
#include <iostream> boost::atomic<int> a{}; void thread()
{
++a;
} int main()
{
std::thread t1{thread};
std::thread t2{thread};
t1.join();
t2.join();
std::cout << a << '\n';
}

之前用的编译命令为:

/opt/compiler/gcc-4.8.2/bin/g++ test.cpp -I ./boost/include -std=c++11

需要改为:

/opt/compiler/gcc-4.8.2/bin/g++ test.cpp -I ./boost/include -std=c++11 -lpthread -Wl,--no-as-needed

这样运行就不会报错了。

本文参考自:https://stackoverflow.com/questions/19463602/compiling-multithread-code-with-g#

Enable multithreading to use std::thread: Operation not permitted问题解决的更多相关文章

  1. linux每日一练:Enable multithreading to use std::thread: Operation not permitted问题解决

    linux每日一练:Enable multithreading to use std::thread: Operation not permitted问题解决 在linux在需要使用c++11时会遇到 ...

  2. "npm ERR! Error: EPERM: operation not permitted"问题解决

    在基于macaca进行自动化测试的时候,遇到如下问题: E:\AutoTest\Macaca\LocalTEST\macaca-test-sample\macaca-test>macaca do ...

  3. C++ std::thread

    std::thread Defined in header class thread The class thread represents a single thread of execution. ...

  4. C++11 并发指南------std::thread 详解

    参考: https://github.com/forhappy/Cplusplus-Concurrency-In-Practice/blob/master/zh/chapter3-Thread/Int ...

  5. std::thread使用

    本文将从以下三个部分介绍C++11标准中的thread类,本文主要内容为: 启动新线程 等待线程与分离线程 线程唯一标识符 1.启动线程 线程再std::threada对象创建时启动.最简单的情况下, ...

  6. std::thread

    std::shared_ptr<std::thread> m_spThread; m_spThread.reset(new std::thread(std::bind(&GameS ...

  7. 用std::thread替换实现boost::thread_group

    thread_group是boost库中的线程池类,内部使用的是boost::thread. 随着C++ 11标准的制定和各大编译器的新版本的推出(其实主要是VS2012的推出啦……),本着能用标准库 ...

  8. C++ 11 笔记 (五) : std::thread

    这真是一个巨大的话题.我猜记录完善绝B需要一本书的容量. 所以..我只是略有了解,等以后用的深入了再慢慢补充吧. C++写多线程真是一个痛苦的事情,当初用过C语言的CreateThread,见过boo ...

  9. Cocos2dx 3.0 过渡篇(二十六)C++11多线程std::thread的简单使用(上)

    昨天练车时有一MM与我交替着练,聊了几句话就多了起来,我对她说:"看到前面那俩教练没?老色鬼两枚!整天调戏女学员."她说:"还好啦,这毕竟是他们的乐趣所在,你不认为教练每 ...

随机推荐

  1. 【FireMonkey】StyleBook使用方法

    近期在开发一个团队文档管理工具,使用Embarcadero的XE2-C++builder进行界面开发,使用Firemonkey框架. 而这个框架十分有趣!可能吸引界面开发者的就是这个StyleBook ...

  2. python 协程的学习记录

    协程是个子程序,执行过程中,内部可中断,然后转而执行别的子程序,在适当的时候再返回来接着执行 从句法上看,协程与生成器类似,都是定义体中包含 yield 关键字的函数.可是,在协程中,yield 通常 ...

  3. 文本域光标操作(选、添、删、取)的jQuery扩展

    ; (function ($) { /* * 文本域光标操作(选.添.删.取)的jQuery扩展 @Mr.Think http://mrthink.net/text-field-jquery-exte ...

  4. 《大话操作系统——做坚实的project实践派》(5)

    有人说我不是仅仅会玩X86吗?我如今铁板钉钉的申明:我事实上兼通:ARM.IA-32.IA-32e.AMD64. ​了解MIPS.但没做过MIPS由于确实没有对应的MIPS硬件平台. ​

  5. git使用中的一些问题

    ubuntu14.04中从服务器下代码出错如下: yingc@yingc:/media/sf_yingc/work/gitcode/androidtv$ repo sync boxThe authen ...

  6. vue - webpack.base.conf.js

    描述:webapck基本配置文件. 为了给开发文件和打包文件(webpack.dev.conf.js|| webpack.prod.conf.js) 提供方便. 'use strict' // 路径 ...

  7. Building An Effective Marketing Plan

    “New ideas are a dime a dozen,” observes Arthur R. Kydd, “and so are new products and new technologi ...

  8. ES6 变量解构用法

    1.数组解构,可以设置默认值 'use strict'; let [x, y = 'b'] = ['a']; //控制台输出b console.log(y); 2.对象解构 'use strict'; ...

  9. CXF调用方式——使用wsdl2java(Windwos下)

    1.自动生成客户端代码: 先把CXF下到本地,本例中我下的是apache-cxf-3.1.2,然后在命令行里到相应路径执行命令: D:\soft\DevelopSoft\apache-cxf-\bin ...

  10. Docker背后的内核知识——cgroups资源限制(转)

    时间 2015-04-20 21:10:00 InfoQ 原文  http://www.infoq.com/cn/articles/docker-kernel-knowledge-cgroups-re ...