Hello,
I am trying to get this program working
#include <iostream>
#include <thread>
#include <future>
using namespace std;
void initiazer(std::promise<int> * promObj)
{
std::cout<<"Inside Thread"<<std::endl; promObj->set_value(35);
}
int main()
{
std::promise<int> promiseObj;
std::future<int> futureObj = promiseObj.get_future();
std::thread th(initiazer, &promiseObj);
std::cout<<futureObj.get()<<std::endl;
th.join();
return 0;
}
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted
Process returned 134
I went to PROJECT --> BUILD OPTIONS --> [Select project name in top left] --> Check -std=c++11
then under
LINKER SETTINGS --> OTHER LINKER OPTIONS --> I typed -pthread
Why wont this application compile?
Thanks in advance
http://stackoverflow.com/questions/19463602/compiling-multithread-code-with-g
It's not related to CodeBlocks
Yves
Thank you for the response. I realize this is not related to code blocks directly but my question is how do I configure codeblocks with these options.
I saw the thread that you posted before I created this thread.
I go to PROJECT --> BUILD OPTIONS --> [Select project name in top left] --> OTHER COMPILER OPTIONS -->
In the box i append one of the following (I have tried all 3 and none work)
-pthread -lpthread -Wl,--no-as-needed
or
or
-Wl,--no-as-needed -lpthread
Am I typing this in the correct spot? my g++ is 4.8.4
Thanks to any information you guys can provide
If i bypass codeblocks completely then it works
$ g++ -c main.cpp -pthread -std=c++11
$ g++ main.o -o main.out -pthread -std=c++11
$ ./main.out
Inside Thread
35
this code will compile in codeblocks but the program will not execute (it gives the original error)
EDIT:
clean your project and it will work