Would you please help me spot what I’m doing wrong here. I’m starting to feel like there is a bug or something.
The code does something like the following:
using namespace boost::asio;
using namespace std::chrono;
using namespace std::chrono_literals;
io_context io;
executor_work_guard<io_context::executor_type> keepRunning(io.get_executor());
std::thread t{io::context::run, &io};
steady_timer timer(io);
timer.expires_after(100ms);
timer.async_wait(()(boost::system::error_code){}); // This is technically a one shot-timer with.
std::this_thread::sleep_for(500ms);
// Here comes the problem
io.stop();
t.join(); // This gets stuck for 5 minutes every time. The thread is still executing io_context::run
Now, if I do the same exact thing with a timeout handler that continues call async_wait, then io.stop() correctly aborts the timer. Calling timer.cancel() before calling io.stop() doesn’t help either.
I must be missing something but the 5 minute timeout is strangely similar to the default TCP timeout… as if there is a a select with that as a default timeout. Help me please!
I’m using boost version 1.72.0 with VS2019 on windows 10 x64.