Imagine in a multithreaded context we have three or more independent strands each serializing access to some resource:
boost::asio::io_context ioc;
auto io_ex = ioc.get_executor();
auto strand_a = boost::asio::make_strand(io_ex);
auto strand_b = boost::asio::make_strand(io_ex);
auto strand_c = boost::asio::make_strand(io_ex);
// TODO: schedule handler on all three strands
std::jthread threads[3]; // provide enough threads to serve strands in parallel
for (auto& thread : threads)
thread = std::jthread{ [&]() { ioc.run(); }};
How can we archive to run a single handler in all strands at once, allowing to safely access all resources simultaneously from within this single hander?