Note that there are some explanatory texts on larger screens.

plurals
  1. POC++11 async segmentation fault
    primarykey
    data
    text
    <p>Can someone explain what I am doing wrong here:</p> <pre><code>#include &lt;future&gt; #include &lt;iostream&gt; int main() { std::future&lt;int&gt; result( std::async([](int m) { return m+1;}, 2)); std::cout &lt;&lt; "In main" &lt;&lt; std::endl; std::cout &lt;&lt; result.get(); } </code></pre> <p>With GCC 4.8 or 4.9, I get a segmentation fault. : </p> <pre><code>./a.out: In main Segmentation fault: 11 : /opt/local/bin/g++-mp-4.8 -v Using built-in specs. COLLECT_GCC=/opt/local/bin/g++-mp-4.8 COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.8.1/lto-wrapper Target: x86_64-apple-darwin12 Configured with: ../gcc-4.8.1/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.8 --with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc48 4.8.1_0' Thread model: posix gcc version 4.8.1 (MacPorts gcc48 4.8.1_0) </code></pre> <p>Edit: Some people have pointed to another answer that says link with pthread. That does not solve the problem:</p> <pre><code>: /opt/local/bin/g++-mp-4.8 -std=c++11 -lpthread thread5.cc : ./a.out In main Segmentation fault: 11 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload