Skip to content

when_all() appears to ignore the passed-in executor #169

@TheMartin

Description

@TheMartin

The documentation page on when_all has this to say:

This function create a joining future. When all passed args futures are fulfilled, then the continuation tasks defined with f is scheduled on the executor e.

It even describes the parameter e as "Executor which is used to schedule the resulting task".

That would lead me to believe that the following test cases should pass:

BOOST_FIXTURE_TEST_SUITE(future_when_all_scheduling, test_fixture<void>)
BOOST_AUTO_TEST_CASE(future_when_all_args)
{
  auto f1 = make_ready_future(custom_scheduler<0>());
  auto f2 = make_ready_future(custom_scheduler<0>());
  sut = when_all(custom_scheduler<1>(), []{}, f1, f2);

  wait_until_future_completed(sut);

  BOOST_REQUIRE_LE(1, custom_scheduler<1>::usage_counter());
}

BOOST_AUTO_TEST_CASE(future_when_all_range)
{
  future<void> fs[] = { make_ready_future(custom_scheduler<0>()), make_ready_future(custom_scheduler<0>()) };
  sut = when_all(custom_scheduler<1>(), []{}, std::pair{ std::begin(fs), std::end(fs) });

  wait_until_future_completed(sut);

  BOOST_REQUIRE_LE(1, custom_scheduler<1>::usage_counter());
}
BOOST_AUTO_TEST_SUITE_END()

However, in both cases, custom_scheduler<1>::usage_counter() is 0. The continuation appears to always run immediately as part of the last future becoming ready; it isn't even scheduled on custom_scheduler<0>. To me, this is surprising behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions