Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

experimental::make_parallel_group (3 of 3 overloads)

Create a group of operations that may be launched in parallel.

template<
    typename Allocator,
    typename Range>
ranged_parallel_group< typename std::decay< Range >::type, Allocator > make_parallel_group(
    allocator_arg_t ,
    const Allocator & allocator,
    Range && range,
    typename constraint< is_async_operation_range< typename std::decay< Range >::type >::value >::type  = 0);
Parameters

allocator

Specifies the allocator to be used with the result vectors.

range

A range containing the operations to be launched.

For example:

using op_type = decltype(
    socket1.async_read_some(
      boost::asio::buffer(data1),
      boost::asio::deferred
    )
  );

std::vector<op_type> ops;

ops.push_back(
    socket1.async_read_some(
      boost::asio::buffer(data1),
      boost::asio::deferred
    )
  );

ops.push_back(
    socket2.async_read_some(
      boost::asio::buffer(data2),
      boost::asio::deferred
    )
  );

boost::asio::experimental::make_parallel_group(
    std::allocator_arg_t,
    my_allocator,
    ops
  ).async_wait(
    boost::asio::experimental::wait_for_all(),
    [](
        std::vector<std::size_t> completion_order,
        std::vector<boost::system::error_code> e,
        std::vector<std::size_t> n
      )
    {
      for (std::size_t i = 0; i < completion_order.size(); ++i)
      {
        std::size_t idx = completion_order[i];
        std::cout << "socket " << idx << " finished: ";
        std::cout << e[idx] << ", " << n[idx] << "\n";
      }
    }
  );

PrevUpHomeNext