-1

I have written a simple code to test threading in C++11. But I can't run it in Clion IDE, it gives following error in red lines.

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

Process finishes with exit code 134.

some details about my system :

  • linux ubuntu 14.10
  • C++11

I guess the code is not that important to solve this problem, but I am pasting it here:

#include <iostream>
#include <thread>

using namespace std;

void task1 () {
    cout << "Task 1::"<<endl;
}

int main() {
    thread t1(task1);
    t1.join();
    return 0;
}
jbsu32
  • 1,036
  • 1
  • 11
  • 31

1 Answers1

6

In the CMakeList.txt file of my project, I just added one command -pthread to the the following line

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

So that looks like

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")

It solves the problem.

jbsu32
  • 1,036
  • 1
  • 11
  • 31