Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/capy/ex/run.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ struct [[nodiscard]] run_awaitable_ex
env_.frame_allocator = caller_env->frame_allocator;

p.set_environment(&env_);
return h;
return ex_.dispatch(h);
}

// Non-copyable
Expand Down
33 changes: 33 additions & 0 deletions test/unit/ex/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include "test/unit/custom_task.hpp"
#include "test/unit/test_helpers.hpp"

#include <boost/capy/ex/strand.hpp>
#include <boost/capy/ex/thread_pool.hpp>

#include <latch>
#include <memory>

namespace boost {
Expand Down Expand Up @@ -468,6 +472,34 @@ struct run_test
BOOST_TEST(result);
}

void
testRunExStrandFirstInstruction()
{
// Verify that the first instructions of a task passed
// to run(strand) execute inside the strand's serialization,
// not inline on an unprotected thread.
thread_pool pool(2, "str-pool-");
strand s(pool.get_executor());
bool inside_strand = false;
std::latch done(1);

auto inner = [&]() -> task<void> {
inside_strand = s.running_in_this_thread();
co_return;
};

auto outer = [&]() -> task<void> {
co_await capy::run(s)(inner());
};

run_async(pool.get_executor(),
[&]() { done.count_down(); })(outer());
done.wait();

BOOST_TEST(inside_strand);
pool.join();
}

void
run()
{
Expand All @@ -490,6 +522,7 @@ struct run_test
testStopTokenOverrideOuterStopped();
testAllocatorPropagation();
testAllocatorPropagationThroughRun();
testRunExStrandFirstInstruction();
}
};

Expand Down
Loading