Unable to execute thread


#1

I running a code in c++ and getting the error:
terminate called after throwing an instance of 'std::system_error’
what(): Enable multithreading to use std::thread: Operation not permitted

didn’t work after adding -Wl,–no-as-needed and -lpthread…

I try to run it on the bash and it’s working but I still want to run it with the regular run function(known as f5)
simple example:

#include <iostream>       // std::cout
#include <thread>         // std::thread
 
void foo() 
{
  // do stuff...
}

void bar(int x)
{
  // do stuff...
}

int main() 
{
  std::thread first (foo);     // spawn new thread that calls foo()
  std::thread second (bar,0);  // spawn new thread that calls bar(0)

  std::cout << "main, foo and bar now execute concurrently...\n";

  // synchronize threads:
  first.join();                // pauses until first finishes
  second.join();               // pauses until second finishes

  std::cout << "foo and bar completed.\n";

  return 0;
}

#2

please show commands you used to run this from commandline, and the runner you used for f5


#3

my command for bash to compile is : g++ -Wl,–no-as-needed -std=c++11 -lpthread simple_thread.cpp -o simple_thread.out
and I try to run it by clicking on simple_thread.cpp file and click on the run option…
I will appreciate if u can help me as soon as possible, have a great day…


#4

In the the runner name popup there is “Edit Runner” menu item, use it to add -Wl,--no-as-needed -lpthread arguments to g++ call in it:

// This file overrides the built-in C++ (simple) runner
// For more information see http://docs.c9.io:8080/#!/api/run-method-run
{
  "script": [
    "set -e",
    "if [ \"$debug\" == true ]; then ",
    "   g++ -Wl,--no-as-needed  -lpthread -ggdb3 -std=c++11 $file -o $file.o",
    "   chmod 755 \"$file.o\"",
    "   node $HOME/.c9/bin/c9gdbshim.js \"$file.o\" $args",
    "else",
    "   g++ -Wl,--no-as-needed -std=c++11 -lpthread $file -o $file.o",
    "   chmod 755 $file.o",
    "   $file.o $args",
    "fi"
  ],
  "info": "Running $file",
  "debugger": "gdb",
  "$debugDefaultState": false,
  "env": {},
  "selector": "^.*\\.(cpp|cc)$"
}

#5

hi and thanks for your help but still after making the changes in the edit runner , the problem stay the same.
please keep on helping me …:scream:


#6

could you modify info attribute of the runner, or add echo something to make sure new runner is used


#7

I’m not sure where should I add the echo message for testing the runner


#8

add it after “set -e” line, something like:

// This file overrides the built-in C++ (simple) runner
// For more information see http://docs.c9.io:8080/#!/api/run-method-run
{
  "script": [
    "set -e",
    "echo new runner is running here =================",
    "if [ \"$debug\" == true ]; then ",

#9

i add the line as u show me and still get the same error without seeing the echo line…


#10

could you tell me the url of your workspace?


#11

maybe I had to restart c9 because suddenly the file run but it work only one time


#12

My url is - https://ide.c9.io/eladliss/search_engine
sorry but for some reason I got the same issue again.
it seems that the program doesn’t use the editor we change constantly.


#13

could you check if there are any errors in the browser console.
And try to open the ide in chrome or firefox