Subject: [Boost-bugs] [Boost C++ Libraries] #7552: win_iocp_io_service hangs due to a race condition
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-10-22 14:31:12
#7552: win_iocp_io_service hangs due to a race condition
-----------------------------------+----------------------------------------
Reporter: danielg@⦠| Owner: chris_kohlhoff
Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
Version: Boost 1.49.0 | Severity: Regression
Keywords: asio windows hang |
-----------------------------------+----------------------------------------
The fix to #6321 introduced a bug that can cause the io_service to hang.
Example code (hangs eventually):
{{{
int main()
{
for (;;)
{
boost::asio::io_service ios;
ios.post([]{ std::cout << '.'; });
boost::thread_group threads;
for (size_t i = 0; i < 2; ++i)
threads.create_thread([&]{ ios.run(); });
threads.join_all();
}
}
}}}
Suppose that one of the threads read the posted operation, completed it
and got to the ''work_finished'' function where it decremented
''outstanding_work'' to 0 and entered the ''stop'' function. Now the
second thread starts. In the ''run'' function it sees that
''outstanding_work'' is 0 so it sets ''stopped'' to 1 and returns. Back in
the first thread ''PostQueuedCompletionStatus(iocp_.handle, 0, 0, 0)''
isn't called since ''stopped'' is already 1. ''do_one'' returns 1 and is
called again. ''GetQueuedCompletionStatus'' returns WAIT_TIMEOUT because
the operation queue is empty, which causes the loop to continue to the
next iteration ad infinitum.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7552> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC