From 00ec93a8ed608d40baa6e033e7ff77f2e828bfb8 Mon Sep 17 00:00:00 2001 From: Jim Wong Date: Wed, 24 Dec 2014 13:52:02 -0800 Subject: [PATCH] Don't release lock until after signaling condition. Original description (from Ben): This fixes a race in task_io_service where the event_object is protected by the lock, and releasing the lock allows it to be deleted before the condition is signaled. See also: https://svn.boost.org/trac/boost/ticket/10213#comment:2 --- include/boost/asio/detail/posix_event.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/asio/detail/posix_event.hpp b/include/boost/asio/detail/posix_event.hpp index 9b633af7..53d3124a 100644 --- a/include/boost/asio/detail/posix_event.hpp +++ b/include/boost/asio/detail/posix_event.hpp @@ -66,9 +66,9 @@ class posix_event BOOST_ASIO_ASSERT(lock.locked()); state_ |= 1; bool have_waiters = (state_ > 1); - lock.unlock(); if (have_waiters) ::pthread_cond_signal(&cond_); // Ignore EINVAL. + lock.unlock(); } // If there's a waiter, unlock the mutex and signal it. @@ -79,8 +79,8 @@ class posix_event state_ |= 1; if (state_ > 1) { - lock.unlock(); ::pthread_cond_signal(&cond_); // Ignore EINVAL. + lock.unlock(); return true; } return false;