]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
testsuite: Prevent the main thread from starving the worker threads
authorPeter Palfrader <peter@palfrader.org>
Mon, 12 Apr 2010 22:10:56 +0000 (00:10 +0200)
committerNick Mathewson <nickm@torproject.org>
Mon, 12 Apr 2010 22:15:20 +0000 (18:15 -0400)
changes/weasel-testuite-thread-fixes
src/or/test.c

index 8fed7297d7ad1059df56a9448fbbae1219a75728..4c32c3881acea2a302a2dd473b4e25f5864d3c4c 100644 (file)
@@ -1,3 +1,8 @@
   o Minor bugfixes:
     - Testsuite:  In the util/threads test no longer free the test_mutex
       before all worker threads have finished.
+    - Testsuite:  The master thread could starve the worker threads quite
+      badly on certain systems, causing them to run only partially in
+      the allowed window.  This resulted in test failures.  Now the master
+      thread sleeps occasionally for a few microseconds while the two
+      worker-threads compete for the mutex.
index 652a4ee44fad2c5b692f9b7ba7e7ee23b792b014..14ba953544c6ad0dc2d15a6c749c169ec0493d79 100644 (file)
@@ -2326,6 +2326,11 @@ test_util_threads(void)
   char *s1 = NULL, *s2 = NULL;
   int done = 0, timedout = 0;
   time_t started;
+#ifndef MS_WINDOWS
+  struct timeval tv;
+  tv.tv_sec=0;
+  tv.tv_usec=10;
+#endif
 #ifndef TOR_IS_MULTITHREADED
   /* Skip this test if we aren't threading. We should be threading most
    * everywhere by now. */
@@ -2355,6 +2360,10 @@ test_util_threads(void)
       timedout = done = 1;
     }
     tor_mutex_release(_thread_test_mutex);
+#ifndef MS_WINDOWS
+    /* Prevent the main thread from starving the worker threads. */
+    select(0, NULL, NULL, NULL, &tv);
+#endif
   }
 
   tor_mutex_acquire(_thread_test_start1);