std::async should work with 4.7.1, but it doesn't?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I can compile

---

#include <iostream>
#include <vector>
#include <numeric>
#include <future>
 
template <typename RAIter>
int parallel_sum(const RAIter beg, const RAIter end) {
  const auto len = end-beg;
  if(len < 1000) return std::accumulate(beg, end, 0);
 
  const RAIter mid = beg + len/2;
  auto handle = std::async(std::launch::async, parallel_sum<RAIter>, mid, end);
  const int sum = parallel_sum(beg, mid);
  return sum + handle.get();
}
 
int main() {
  std::vector<int> v(10000, 1);
  std::cout << "The sum is " << parallel_sum(v.begin(), v.end()) << ".\n";
}

---

using "g++ -Wall -std=c++11", but running it I get

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

The program should be correct (btw, it is adapted from
 http://en.cppreference.com/w/cpp/thread/async ).

The system is:

> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.7/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.7 --enable-ssp --disable-libssp --disable-libitm --disable-plugin --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --enable-linker-build-id --program-suffix=-4.7 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.7.1 20120723 [gcc-4_7-branch revision 189773] (SUSE Linux) 

> uname -a
Linux XXX 3.4.42-2.28-desktop #1 SMP PREEMPT Mon Apr 29 09:18:32 UTC 2013 (a7a14eb) x86_64 x86_64 x86_64 GNU/Linux

Any help would be appreciated.

Oliver





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux