Boost logo

Boost Users :

Subject: [Boost-users] [Thread] Problems compiling an example from the docs
From: Malko (malko.bravi_at_[hidden])
Date: 2015-10-14 13:02:21


Hi, I am trying to compile the following example:
http://www.boost.org/doc/libs/1_59_0/doc/html/thread/synchronization.html#thread.synchronization.futures.async

#include <boost/thread.hpp>
#include <boost/thread/future.hpp>

int parallel_sum(int* data, int size)
{
  int sum = 0;
  if ( size < 1000 )
    for ( int i = 0; i < size; ++i )
      sum += data[i];
  else {
    boost::future<int> handle = boost::async(parallel_sum, data+size/2,
size-size/2);
    sum += parallel_sum(data, size/2);
    sum += handle.get();
  }
  return sum;
}

int main() {
  int data[] = {1,2,3,4,5,6,7,8,9,10};
  int a(parallel_sum, data, 10);
  return 0;
}

It does not compile because future is not a type in boost and async has the
wrong signature.
The future error goes away by defining BOOST_THREAD_PROVIDES_FUTURE, but I
can not find this mentioned anywhere in the docs, I found out only looking
on stack overflow.
The async signature seems to require a function of arity 0.

This is clang 3.4 output using Boost.1.59 and C++03:

XXX/src/futtest.cpp:12:33: error: no matching function for call to 'async'
    boost::future<int> handle = boost::async(parallel_sum, data+size/2,
size-size/2);
                                ^~~~~~~~~~~~
   
/home/dev/build/third_party/64-rhel5/boost_1_59_0/include/boost/thread/future.hpp:3545:3:
note: candidate function template not viable: requires 2 arguments, but 3
were provided
  async(launch policy, R(*f)()) {
  ^
   
/home/dev/build/third_party/64-rhel5/boost_1_59_0/include/boost/thread/future.hpp:3609:3:
note: candidate function template not viable: requires 2 arguments, but 3
were provided
  async(launch policy, BOOST_THREAD_FWD_REF(F) f) {
  ^
   
/home/dev/build/third_party/64-rhel5/boost_1_59_0/include/boost/thread/future.hpp:3961:3:
note: candidate function template not viable: requires single argument 'f',
but 3 arguments were provided
  async(R(*f)()) {
  ^
   
/home/dev/build/third_party/64-rhel5/boost_1_59_0/include/boost/thread/future.hpp:3978:3:
note: candidate function template not viable: requires single argument 'f',
but 3 arguments were provided
  async(BOOST_THREAD_FWD_REF(F) f) {
  ^
XXX/src/futtest.cpp:22:7: error: excess elements in scalar initializer

Is there more macro to be used to enable this to compile?

Thanks

P.S.
It would be nice to have all the info about macro configuration for future
(and async, if it has any) in the docs.

--
View this message in context: http://boost.2283326.n4.nabble.com/Thread-Problems-compiling-an-example-from-the-docs-tp4680921.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net