From 624d9b8efb1267ba8c3ed5d82a4ee48ad04e42b2 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Tue, 7 May 2019 17:23:42 -0700 Subject: [PATCH] Handle the case when the SamplingProfiler thread is terminated prematurely --- src/vm/sampleprofiler.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/vm/sampleprofiler.cpp b/src/vm/sampleprofiler.cpp index 4b8e8b5..8fb9769 100644 --- a/src/vm/sampleprofiler.cpp +++ b/src/vm/sampleprofiler.cpp @@ -113,16 +113,23 @@ void SampleProfiler::Disable() return; } - // Reset the event before shutdown. - s_threadShutdownEvent.Reset(); + // If g_fProcessDetach is true, the sampling profiler thread probably got + // ripped because someone called ExitProcess(). This check is an attempt + // to recognize that case and avoid waiting for the (already dead) sampling + // profiler thread to tell us it is terminated. + if (!g_fProcessDetach) + { + // Reset the event before shutdown. + s_threadShutdownEvent.Reset(); - // The sampling thread will watch this value and exit - // when profiling is disabled. - s_profilingEnabled = false; + // The sampling thread will watch this value and exit + // when profiling is disabled. + s_profilingEnabled = false; - // Wait for the sampling thread to clean itself up. - s_threadShutdownEvent.Wait(INFINITE, FALSE /* bAlertable */); - s_threadShutdownEvent.CloseEvent(); + // Wait for the sampling thread to clean itself up. + s_threadShutdownEvent.Wait(INFINITE, FALSE /* bAlertable */); + s_threadShutdownEvent.CloseEvent(); + } if(s_timePeriodIsSet) { -- 2.7.4