Boost C++ Libraries: Ticket #12690: Boost Asio race condition https://svn.boost.org/trac10/ticket/12690 <p> The following test case issues an warning when executed with the thread sanitizer. The problem occurs when there is a pending job and the associated work is canceled. </p> <pre class="wiki">BOOST_AUTO_TEST_CASE(ioServiceShallWaitForPendingJobs) { auto test = []() { boost::asio::io_service service; std::unique_ptr&lt;boost::asio::io_service::work&gt; work (new boost::asio::io_service::work(service)); std::thread t( [&amp;service]() { service.run(); } ); std::atomic_bool called{false}; service.post( [&amp;called]() { std::this_thread::sleep_for (std::chrono::milliseconds(50)); called = true; } ); std::this_thread::sleep_for (std::chrono::milliseconds(1)); work.reset(); // -&gt; race t.join(); BOOST_REQUIRE(called); }; for( size_t i = 0 ; i &lt; 100000; ++i) { BOOST_TEST_MESSAGE(i); test(); } } </pre><p> The fix is in asio/detail/posix_event.hpp:55 </p> <pre class="wiki"> // Signal the event and unlock the mutex. template &lt;typename Lock&gt; void signal_and_unlock(Lock&amp; lock) { BOOST_ASIO_ASSERT(lock.locked()); signalled_ = true; // lock.unlock(); ::pthread_cond_signal(&amp;cond_); // Ignore EINVAL. lock.unlock(); // first signal and then unlock as the name implies } </pre><p> Please find the output of the Clang as an attachment </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12690 Trac 1.4.3 Ivan Kostov <ikostov@…> Wed, 14 Dec 2016 14:40:06 GMT attachment set https://svn.boost.org/trac10/ticket/12690 https://svn.boost.org/trac10/ticket/12690 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ClangThreadSanitizer.txt</span> </li> </ul> Ticket