From 8adb509c633e7c1e992d31819d2d99fe5a093443 Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Fri, 12 Aug 2011 23:13:38 -0400 Subject: [PATCH] [threadpool] Work around for a race-condition Under some circumstances new_job was not signaled and the threadpool threads didn't realized there was a workitem in the queue. Fixes Xamarin bug #12 and Novell bug #690357. --- mono/metadata/threadpool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mono/metadata/threadpool.c b/mono/metadata/threadpool.c index e74f498a247..14cd9dd25ad 100644 --- a/mono/metadata/threadpool.c +++ b/mono/metadata/threadpool.c @@ -1470,9 +1470,9 @@ async_invoke_thread (gpointer data) InterlockedIncrement (&tp->waiting); #if defined(__OpenBSD__) - while ((res = mono_sem_wait (&tp->new_job, TRUE)) == -1) {// && errno == EINTR) { + while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_wait (&tp->new_job, TRUE)) == -1) {// && errno == EINTR) { #else - while ((res = mono_sem_timedwait (&tp->new_job, 2000, TRUE)) == -1) {// && errno == EINTR) { + while (mono_cq_count (tp->queue) == 0 && (res = mono_sem_timedwait (&tp->new_job, 2000, TRUE)) == -1) {// && errno == EINTR) { #endif if (mono_runtime_is_shutting_down ()) break; -- 2.25.1