[threadpool-ms] Fix race condition
authorLudovic Henry <ludovic.henry@xamarin.com>
Thu, 23 Apr 2015 19:47:26 +0000 (20:47 +0100)
committerLudovic Henry <ludovic.henry@xamarin.com>
Thu, 23 Apr 2015 19:47:26 +0000 (20:47 +0100)
mono/metadata/threadpool-ms.c

index 66689009ffec2643014e6ba37226ddef646b685f..6038160548e7f09e345a87183369cdf555988ad5 100644 (file)
@@ -757,7 +757,7 @@ monitor_should_keep_running (void)
 
        if (InterlockedExchange (&monitor_status, MONITOR_STATUS_WAITING_FOR_REQUEST) == MONITOR_STATUS_WAITING_FOR_REQUEST) {
                if (mono_runtime_is_shutting_down () || !domain_any_has_request ()) {
-                       if (InterlockedExchange (&monitor_status, MONITOR_STATUS_NOT_RUNNING) == MONITOR_STATUS_WAITING_FOR_REQUEST)
+                       if (InterlockedCompareExchange (&monitor_status, MONITOR_STATUS_NOT_RUNNING, MONITOR_STATUS_WAITING_FOR_REQUEST) == MONITOR_STATUS_WAITING_FOR_REQUEST)
                                return FALSE;
                }
        }