Skip to content

Commit

Permalink
Replace unneeded explicit memory barrier with Volatile.Write
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jan 14, 2021
1 parent 9f3fb63 commit 03ad246
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Shared/NonCapturingLazyInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ public static TValue EnsureInitialized<TParam, TValue>(
return value;
}

target = valueFactory(param);
Thread.MemoryBarrier();
initialized = true;
Volatile.Write(ref target, valueFactory(param));
Volatile.Write(ref initialized, true);

return target;
}
Expand Down

0 comments on commit 03ad246

Please sign in to comment.