You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is an example code which demonstrates the issue (boost 1.87, VS2022, Win10):
#include<boost/asio/thread_pool.hpp>
#include<boost/asio/awaitable.hpp>
#include<boost/asio/use_awaitable.hpp>
#include<boost/asio/co_spawn.hpp>
#include<boost/asio/detached.hpp>
#include<boost/asio/this_coro.hpp>
#include<boost/asio/as_tuple.hpp>
#include<boost/asio/experimental/awaitable_operators.hpp>
#include<boost/asio/experimental/concurrent_channel.hpp>
#include<syncstream>
#include<iostream>
boost::asio::awaitable<void> send_to_channel(
boost::asio::experimental::concurrent_channel<void()>& ch)
{
co_awaitboost::asio::this_coro::throw_if_cancelled(false);
std::osyncstream(std::cerr) << "Sending to channel...\n";
auto [ec] = co_await ch.async_send(boost::asio::as_tuple(boost::asio::use_awaitable));
std::osyncstream(std::cerr) << "Error " << ec << "\n";
}
intmain()
{
boost::asio::thread_pool ctx{ 20 };
boost::asio::experimental::concurrent_channel<void()> ch(ctx);
usingnamespaceboost::asio::experimental::awaitable_operators;for (int i = 0; i < 50; ++i)
{
boost::asio::co_spawn(ctx, send_to_channel(ch),
boost::asio::detached);
}
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cerr << "Closing channel!\n";
// I would expect this call to cancel all outstanding async// operations, but this does not happen.
ch.close();
ctx.join();
}
The program just hangs, and the last line in the output I see is "Closing channel!".
If I call ch.cancel() after close(), this does cancel the pending operations, however, the error code I get is 0 (no error), which is also unexpected. According to the manual, it should be boost::asio::experimental::error::channel_cancelled instead.
The text was updated successfully, but these errors were encountered:
dragon-dreamer
changed the title
Closing the concurrent channel does not cancel outstanding async operations
Closing the concurrent channel does not cancel outstanding async operations. Cancelling produces wrong error code
Dec 22, 2024
Here is an example code which demonstrates the issue (boost 1.87, VS2022, Win10):
The program just hangs, and the last line in the output I see is "Closing channel!".
If I call
ch.cancel()
afterclose()
, this does cancel the pending operations, however, the error code I get is0
(no error), which is also unexpected. According to the manual, it should beboost::asio::experimental::error::channel_cancelled
instead.The text was updated successfully, but these errors were encountered: