Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Makes CultureInfo.get_Parent thread safe (#8656)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramarag authored and tarekgh committed Dec 16, 2016
1 parent 98c1e2b commit aeae8e1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/mscorlib/src/System/Globalization/CultureInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,29 +893,31 @@ public virtual CultureInfo Parent
get
{
Contract.Ensures(Contract.Result<CultureInfo>() != null);
CultureInfo culture = null;

if (null == m_parent)
{
try
{
string parentName = this.m_cultureData.SPARENT;

if (String.IsNullOrEmpty(parentName))
{
m_parent = InvariantCulture;
culture = InvariantCulture;
}
else
{
m_parent = new CultureInfo(parentName, this.m_cultureData.UseUserOverride);
culture = new CultureInfo(parentName, this.m_cultureData.UseUserOverride);
}
}
catch (ArgumentException)
{
// 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.
m_parent = InvariantCulture;
culture = InvariantCulture;
}

Interlocked.CompareExchange<CultureInfo>(ref m_parent, culture, null);
}
return m_parent;
}
Expand Down

0 comments on commit aeae8e1

Please sign in to comment.