0

Sorry for the dup but I still have this issue.

I'm trying to run the following code:

int main() {
//called_from_async launched in a separate thread if possible
std::future<int> result(
        std::async([](int m, int n) {return m + n;}, 2,
                4));

std::cout << "Message from main." << std::endl;

//retrive and print the value stored in the future
std::cout << result.get() << std::endl;

return 0;
}

Running it i see the following output:

Message from main.
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1
Aborted (core dumped)

After making a small change in 'std::async' call:

int main() {
//called_from_async launched in a separate thread if possible
std::future<int> result(
        std::async(std::launch::async, [](int m, int n) {return m + n;}, 2,
                4));

std::cout << "Message from main." << std::endl;

//retrive and print the value stored in the future
std::cout << result.get() << std::endl;

return 0;
}

i see the following:

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

i use the following command:

 g++  ASYNC_CPP11.cpp -o ASYNC -pthread -std=c++11

the 'gcc -v' command issues the following:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.8.1-10ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9) 

What option i'm missing?

Again, sorry for the dup question. Thank you.

user1053031
  • 727
  • 1
  • 11
  • 30
  • @ComicSansMS The answers to that question (and the question it's marked as a duplicate of) says to use `-pthread` when building, which the OP is already doing. So no duplicate. – Some programmer dude May 23 '14 at 10:51
  • Could you please provide a title that better describes the content of the question? Something that gives an idea of the problem so that someone going through search results won't have to open every single result to see what it is about. – R. Martinho Fernandes May 23 '14 at 10:52
  • Unfortunately change to '-lpthread' didn't help( I checked the question mentioned here but it didn't help too( It seems I have some problems in my environment but so far have no idea what can it be.. – user1053031 May 23 '14 at 10:57
  • R. Martinho Fernandes, is new title ok? – user1053031 May 23 '14 at 11:00
  • @ComicSansMS `-pthread` implies `-lpthread`. – Some programmer dude May 23 '14 at 11:07
  • Yes and i played w/ this compiler/linker options. but issue still exists. I'm going to generate and debug core dump. maybe it will help – user1053031 May 23 '14 at 11:10
  • @JoachimPileborg You are right of course. Sorry for the noise. – ComicSansMS May 23 '14 at 11:11
  • 1
    [Definitively I cannot reproduce your problem](http://coliru.stacked-crooked.com/a/d80a7ec705688ceb) ... :( – Massa May 23 '14 at 14:36
  • Yes, right now i created a solution in eclipse for my local WinGW and everything is fine (running under Win7). So it seems smth. wrong w/ my Ubuntu GCC installation/configuration. BTW, under WinGW I didn't point the -pthread compiler option. Only option for C++11 was needed to run samples. – user1053031 May 24 '14 at 03:32
  • Here is the answer: [-Wl,--no-as-needed][1] [1]: http://stackoverflow.com/a/21130100/1053031 – user1053031 May 26 '14 at 05:05

0 Answers0