在用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. 【JSP EL】<c:if> <c:foreach >EL表达式 获取list长度/不用循环,EL在List中直接获取第一项的内容/EL获取Map的键,Map的值

    1.EL表达式 获取list长度 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" ...

  2. UITabBarControlller 和 UINavigationController

  3. 配置Node Manager启动同一机器的两个域

    进入/u01/FMW_Home/weblogic/wlserver_10.3/server/bin目录,在需要配置的节点上启动node manager,以weblogic用户登录 c d /u01/F ...

  4. latex 三个不同的图放在一行且每个图都有注释

    \begin{figure}[htbp] \begin{minipage}[t]{0.3\linewidth} \centering \includegraphics[width=.2.0.eps} ...

  5. html之marquee会移动的文字

    该标签不是HTML3.2的一部分,并且只支持MSIE3以后内核,所以如果你使用非IE内核浏览器(如:Netscape)可能无法看到下面一些很有意思的效果 该标签是个容器标签 语法: <marqu ...

  6. 流畅的python第一章python数据模型学习记录

    python中有些特殊的方法,以双上下划线开头,并以双下划线结束的方法.如__getitem__,这些方法是特殊的方法,供python解释权内部使用,一般来说不需要调用 还有一种是以双下划线开头的,如 ...

  7. 在安装python的mysqlclient包时报microsoft visual c++ 14.0 is required的错误

    在安装python的mysqlclient包时报microsoft visual c++ 14.0 is required的错误 pip install mysqlclient 提示报错   解决办法 ...

  8. Linux系统443端口被占用无法启动解决办法

    etstat -ano|findstr "443"         //搜索443端口占用情况,并找到进程IDTCP 0.0.0.0:443 0.0.0.0:0 LISTENING ...

  9. scrapy中ROBOTSTXT_OBEY = True的相关说明

    在scrapy中创建项目以后,在settings文件中有这样的一条默认开启的语句: # Obey robots.txt rules ROBOTSTXT_OBEY = True 观察代码可以发现,默认为 ...

  10. 用好Git 和 SVN,轻松驾驭版本管理

    用好Git 和 SVN,轻松驾驭版本管理 本文从 Git 与 SVN 的对比入手,介绍如何通过 Git-SVN 开始使用 Git,并总结平时工作高频率使用到的 Git 常用命令. 一.Git vs S ...