]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Switch order of unblocking threads and releasing the mutex.
authorcypherpunks <cypherpunks@torproject.org>
Thu, 23 Jul 2015 09:28:31 +0000 (11:28 +0200)
committerNick Mathewson <nickm@torproject.org>
Tue, 4 Aug 2015 17:35:02 +0000 (13:35 -0400)
According to POSIX, the mutex must be locked by the thread calling the signal
functions to ensure predictable scheduling behavior.

Found the issue using Helgrind which gave the warning `dubious: associated lock
is not held by any thread`.

changes/bug16644 [new file with mode: 0644]
src/common/workqueue.c

diff --git a/changes/bug16644 b/changes/bug16644
new file mode 100644 (file)
index 0000000..f7126bd
--- /dev/null
@@ -0,0 +1,3 @@
+  o Minor bugfixes (relay):
+    - Unblock threads before releasing the mutex to ensure predictable
+      scheduling behavior. Fixes bug 16644; bugfix on 0.2.6.3-alpha.
index 3f9a063e11758c8e6035ef61e71abc2e7e0ac1b4..cf63634076354ba61f9e0b5f2effafdfdff86135 100644 (file)
@@ -293,10 +293,10 @@ threadpool_queue_work(threadpool_t *pool,
 
   TOR_TAILQ_INSERT_TAIL(&pool->work, ent, next_work);
 
-  tor_mutex_release(&pool->lock);
-
   tor_cond_signal_one(&pool->condition);
 
+  tor_mutex_release(&pool->lock);
+
   return ent;
 }
 
@@ -345,10 +345,10 @@ threadpool_queue_update(threadpool_t *pool,
   pool->update_fn = fn;
   ++pool->generation;
 
-  tor_mutex_release(&pool->lock);
-
   tor_cond_signal_all(&pool->condition);
 
+  tor_mutex_release(&pool->lock);
+
   if (old_args) {
     for (i = 0; i < n_threads; ++i) {
       if (old_args[i] && old_args_free_fn)