From 03ad24683de59824690580a0756d88a5cf7dee74 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Thu, 14 Jan 2021 23:59:20 +0100 Subject: [PATCH] Replace unneeded explicit memory barrier with Volatile.Write --- src/Shared/NonCapturingLazyInitializer.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Shared/NonCapturingLazyInitializer.cs b/src/Shared/NonCapturingLazyInitializer.cs index 4bcbb48548c..9b6d75fab03 100644 --- a/src/Shared/NonCapturingLazyInitializer.cs +++ b/src/Shared/NonCapturingLazyInitializer.cs @@ -86,9 +86,8 @@ public static TValue EnsureInitialized( return value; } - target = valueFactory(param); - Thread.MemoryBarrier(); - initialized = true; + Volatile.Write(ref target, valueFactory(param)); + Volatile.Write(ref initialized, true); return target; }