diff --git a/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/Trace.cs b/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/Trace.cs index 31af00ab0accc5..c4fd3b72d2eb7f 100644 --- a/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/Trace.cs +++ b/src/libraries/System.Diagnostics.TraceSource/src/System/Diagnostics/Trace.cs @@ -4,6 +4,7 @@ #define TRACE using System; using System.Collections; +using System.Threading; namespace System.Diagnostics { @@ -19,18 +20,11 @@ private Trace() } private static CorrelationManager? s_correlationManager; - public static CorrelationManager CorrelationManager - { - get - { - if (s_correlationManager == null) - { - s_correlationManager = new CorrelationManager(); - } - return s_correlationManager; - } - } + public static CorrelationManager CorrelationManager => + Volatile.Read(ref s_correlationManager) ?? + Interlocked.CompareExchange(ref s_correlationManager, new CorrelationManager(), null) ?? + s_correlationManager; /// /// Gets the collection of listeners that is monitoring the trace output.