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;
}