From: Filip Navara Date: Tue, 25 Dec 2018 04:55:30 +0000 (+0100) Subject: Makes CultureInfo.get_Parent thread safe. (dotnet/coreclr#21671) X-Git-Tag: submit/tizen/20210909.063632~11030^2~2997 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7a25839816aae6bffaf36b08b5cee2e10fd49e9;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Makes CultureInfo.get_Parent thread safe. (dotnet/coreclr#21671) Commit migrated from https://github.com/dotnet/coreclr/commit/6d94edc9a794569cd8cf8b300c017b5451f36fd7 --- diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs index f0da4bf..84d7ac2 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs @@ -495,23 +495,26 @@ namespace System.Globalization { if (null == _parent) { + CultureInfo culture = null; string parentName = _cultureData.SPARENT; if (string.IsNullOrEmpty(parentName)) { - _parent = InvariantCulture; + culture = InvariantCulture; } else { - _parent = CreateCultureInfoNoThrow(parentName, _cultureData.UseUserOverride); - if (_parent == null) + culture = CreateCultureInfoNoThrow(parentName, _cultureData.UseUserOverride); + if (culture == null) { // For whatever reason our IPARENT or SPARENT wasn't correct, so use invariant // We can't allow ourselves to fail. In case of custom cultures the parent of the // current custom culture isn't installed. - _parent = InvariantCulture; + culture = InvariantCulture; } } + + Interlocked.CompareExchange(ref _parent, culture, null); } return _parent; }