1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Fixed race in Environment.OperatingSystem and CultureInfo.NumberFormat

This commit is contained in:
Brian Fiete 2024-10-19 05:00:06 -04:00
parent ff2affb733
commit 691c147089
2 changed files with 18 additions and 8 deletions

View file

@ -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;
}
}

View file

@ -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;
}
}