1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +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 get
{ {
var osVersion = new OperatingSystem(); if (sOSVersion == null)
let prevValue = Interlocked.CompareExchange(ref sOSVersion, null, osVersion);
if (prevValue != null)
{ {
// This was already set - race condition var osVersion = new OperatingSystem();
delete osVersion; if (let prevValue = Interlocked.CompareExchange(ref sOSVersion, null, osVersion))
return prevValue; {
// This was already set - race condition
delete osVersion;
return prevValue;
}
} }
return osVersion; return sOSVersion;
} }
} }

View file

@ -74,7 +74,15 @@ namespace System.Globalization
get get
{ {
if (mNumInfo == null) 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; return mNumInfo;
} }
} }