Make exception count performance counter thread-safe (#86018)
authorJan Kotas <jkotas@microsoft.com>
Wed, 10 May 2023 01:46:04 +0000 (18:46 -0700)
committerGitHub <noreply@github.com>
Wed, 10 May 2023 01:46:04 +0000 (18:46 -0700)
Fixes #85997

src/coreclr/vm/exceptionhandling.cpp
src/coreclr/vm/i386/excepx86.cpp

index 02c7398..d960b68 100644 (file)
@@ -195,7 +195,7 @@ void FreeTrackerMemory(ExceptionTracker* pTracker, TrackerMemoryType mem)
 static inline void UpdatePerformanceMetrics(CrawlFrame *pcfThisFrame, BOOL bIsRethrownException, BOOL bIsNewException)
 {
     WRAPPER_NO_CONTRACT;
-    g_exceptionCount++;
+    InterlockedIncrement((LONG*)&g_exceptionCount);
 
     // Fire an exception thrown ETW event when an exception occurs
     ETW::ExceptionLog::ExceptionThrown(pcfThisFrame, bIsRethrownException, bIsNewException);
index 438338e..f0c4dcc 100644 (file)
@@ -1029,7 +1029,7 @@ CPFH_RealFirstPassHandler(                  // ExceptionContinueSearch, etc.
 
         EEToProfilerExceptionInterfaceWrapper::ExceptionThrown(pThread);
 
-        g_exceptionCount++;
+        InterlockedIncrement((LONG*)&g_exceptionCount);
 
     } // End of case-1-or-3