[threadpool] Work around for a race-condition
[mono.git] / mono / metadata / threadpool.c
index e74f498a247b164f1aee09807d8d95be45949a20..14cd9dd25ad81dd92a6d57c552f7adaed8dcefdd 100644 (file)
@@ -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;