Commit 6ed1f476 authored by Pieter Hintjens's avatar Pieter Hintjens

Merge pull request #738 from ricnewton/master

Fix race condition on shutdown
parents 8797af77 844689ed
...@@ -107,7 +107,6 @@ int zmq::ctx_t::terminate () ...@@ -107,7 +107,6 @@ int zmq::ctx_t::terminate ()
// restarted. // restarted.
bool restarted = terminating; bool restarted = terminating;
terminating = true; terminating = true;
slot_sync.unlock ();
// First attempt to terminate the context. // First attempt to terminate the context.
if (!restarted) { if (!restarted) {
...@@ -115,13 +114,12 @@ int zmq::ctx_t::terminate () ...@@ -115,13 +114,12 @@ int zmq::ctx_t::terminate ()
// First send stop command to sockets so that any blocking calls // First send stop command to sockets so that any blocking calls
// can be interrupted. If there are no sockets we can ask reaper // can be interrupted. If there are no sockets we can ask reaper
// thread to stop. // thread to stop.
slot_sync.lock ();
for (sockets_t::size_type i = 0; i != sockets.size (); i++) for (sockets_t::size_type i = 0; i != sockets.size (); i++)
sockets [i]->stop (); sockets [i]->stop ();
if (sockets.empty ()) if (sockets.empty ())
reaper->stop (); reaper->stop ();
slot_sync.unlock ();
} }
slot_sync.unlock();
// Wait till reaper thread closes all the sockets. // Wait till reaper thread closes all the sockets.
command_t cmd; command_t cmd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment