Enable multithreading to use std::thread: Operation not permitted问题解决

背景

在用g++ 4.8.5编译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)

C++支持多线程,有三点注意:

  • 包含头文件#include
  • 编译选项-std=c++11
  • 编译选项-pthread,不添加编译选项-pthread,则运行出现Enable multithreading to use std::thread: Operation not permitted。
  • 选项中指定-lpthread和-pthread一样,建议使用-pthread。

boost中打开多线程编译

修改当前项目的Jamroot/Jamfile文件

project boost_test
    : requirements
	  <cxxflags>"-std=c++11 -g3 -Wl,-v"
	: default-build
	  <debug-symbols>on
	  release
	  <threading>multi
	;

你可能感兴趣的:(Debug,Hacks,linux,多线程)