From a02923122e597e833a987dc38a3b0b8a62e0b122 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 12 Apr 2010 22:49:58 +0200 Subject: [PATCH 1/2] testsuite: Only free the main mutex when and if all the worker threads are done --- changes/weasel-testuite-thread-fixes | 3 +++ src/or/test.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changes/weasel-testuite-thread-fixes diff --git a/changes/weasel-testuite-thread-fixes b/changes/weasel-testuite-thread-fixes new file mode 100644 index 0000000000..8fed7297d7 --- /dev/null +++ b/changes/weasel-testuite-thread-fixes @@ -0,0 +1,3 @@ + o Minor bugfixes: + - Testsuite: In the util/threads test no longer free the test_mutex + before all worker threads have finished. diff --git a/src/or/test.c b/src/or/test.c index 6b7066c385..652a4ee44f 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -2356,13 +2356,14 @@ test_util_threads(void) } tor_mutex_release(_thread_test_mutex); } - tor_mutex_free(_thread_test_mutex); tor_mutex_acquire(_thread_test_start1); tor_mutex_release(_thread_test_start1); tor_mutex_acquire(_thread_test_start2); tor_mutex_release(_thread_test_start2); + tor_mutex_free(_thread_test_mutex); + if (timedout) { printf("\nTimed out: %d %d", t1_count, t2_count); test_assert(strmap_get(_thread_test_strmap, "thread 1")); From 5e679acc72a2648c38a3ee3a2b05cd5b75906568 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Tue, 13 Apr 2010 00:10:56 +0200 Subject: [PATCH 2/2] testsuite: Prevent the main thread from starving the worker threads --- changes/weasel-testuite-thread-fixes | 5 +++++ src/or/test.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/changes/weasel-testuite-thread-fixes b/changes/weasel-testuite-thread-fixes index 8fed7297d7..4c32c3881a 100644 --- a/changes/weasel-testuite-thread-fixes +++ b/changes/weasel-testuite-thread-fixes @@ -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. diff --git a/src/or/test.c b/src/or/test.c index 652a4ee44f..14ba953544 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -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);