From d0f59e7c46891176c6458ad2ad86222c3e285b37 Mon Sep 17 00:00:00 2001 From: sylar Date: Fri, 11 Oct 2024 19:30:12 +0800 Subject: [PATCH] Return if stopped_ is not zero at the begining of loop in do_one --- asio/include/asio/detail/impl/win_iocp_io_context.ipp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/asio/include/asio/detail/impl/win_iocp_io_context.ipp b/asio/include/asio/detail/impl/win_iocp_io_context.ipp index 1c7fb28b2d..5d65bbe6cc 100644 --- a/asio/include/asio/detail/impl/win_iocp_io_context.ipp +++ b/asio/include/asio/detail/impl/win_iocp_io_context.ipp @@ -414,6 +414,13 @@ size_t win_iocp_io_context::do_one(DWORD msec, { for (;;) { + // Check if the context has been stopped + if (::InterlockedExchangeAdd(&stopped_, 0) != 0) + { + ec = asio::error_code(); + return 0; + } + // Try to acquire responsibility for dispatching timers and completed ops. if (::InterlockedCompareExchange(&dispatch_required_, 0, 1) == 1) {