Opened 4 years ago
#13567 new Bugs
io_context ::run() doesn't return immediately on stopped io_context due to Windows implementation
| Reported by: | Owned by: | chris_kohlhoff | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | asio |
| Version: | Boost 1.67.0 | Severity: | Problem |
| Keywords: | windows, io_context, stop, stopped | Cc: |
Description
This code hangs, when running on Windows:
boost::asio::io_context context; // 1
boost::asio::post(context, []() { for (;;); }); // 2
context.stop(); // 3
context.run(); // hangs in a handler, posted in 2
io_context::stop documentation says:
Subsequent calls to run(), run_one(), poll() or poll_one() will return immediately until restart() is called.
Which is, judging by example above, isn't true. Same goes for io_context::stopped:
When an io_context object is stopped, calls to run(), run_one(), poll() or poll_one() will return immediately without invoking any handlers.
and code example below:
boost::asio::io_context context; // 1
boost::asio::post(context, []() { for (;;); }); // 2
context.stop(); // 3
if (context.stopped())
{
context.run(); // hangs in a handler, posted in 2
}
When running on Linux, same code fully complies the documentation and doesn't invoke any handlers in examples provided.
Note:
See TracTickets
for help on using tickets.
