diff --git a/BeefLibs/corlib/src/Environment.bf b/BeefLibs/corlib/src/Environment.bf index da0319b1..d321964f 100644 --- a/BeefLibs/corlib/src/Environment.bf +++ b/BeefLibs/corlib/src/Environment.bf @@ -19,15 +19,17 @@ namespace System { get { - var osVersion = new OperatingSystem(); - let prevValue = Interlocked.CompareExchange(ref sOSVersion, null, osVersion); - if (prevValue != null) + if (sOSVersion == null) { - // This was already set - race condition - delete osVersion; - return prevValue; + var osVersion = new OperatingSystem(); + if (let prevValue = Interlocked.CompareExchange(ref sOSVersion, null, osVersion)) + { + // This was already set - race condition + delete osVersion; + return prevValue; + } } - return osVersion; + return sOSVersion; } } diff --git a/BeefLibs/corlib/src/Globalization/CultureInfo.bf b/BeefLibs/corlib/src/Globalization/CultureInfo.bf index 8b29b163..624d0da7 100644 --- a/BeefLibs/corlib/src/Globalization/CultureInfo.bf +++ b/BeefLibs/corlib/src/Globalization/CultureInfo.bf @@ -74,7 +74,15 @@ namespace System.Globalization get { if (mNumInfo == null) - mNumInfo = new NumberFormatInfo(mCultureData); + { + var numInfo = new NumberFormatInfo(mCultureData); + if (var prevValue = Interlocked.CompareExchange(ref mNumInfo, null, numInfo)) + { + // This was already set - race condition + delete numInfo; + return prevValue; + } + } return mNumInfo; } }