summaryrefslogtreecommitdiff
path: root/src/mscorlib
diff options
context:
space:
mode:
authorGaurav Khanna <gkhanna@microsoft.com>2016-01-28 09:46:36 -0800
committerGaurav Khanna <gkhanna@microsoft.com>2016-01-28 09:46:36 -0800
commita873e6be0473f1a41c5177475ed41e5ec6e5f2ca (patch)
tree81b743c59c74af92d8f1a6346c974ab51230cfc6 /src/mscorlib
parent014c69d7f58998be5ffbc94a49244819f23b9bdd (diff)
parent063f0e706f17d6ccda910bf8ce922b668ab211e5 (diff)
downloadcoreclr-a873e6be0473f1a41c5177475ed41e5ec6e5f2ca.tar.gz
coreclr-a873e6be0473f1a41c5177475ed41e5ec6e5f2ca.tar.bz2
coreclr-a873e6be0473f1a41c5177475ed41e5ec6e5f2ca.zip
Merge pull request #2882 from gkhanna79/FixRace
Fix for CoreCLR issue 2881 - Fix race in Default ALC initialization.
Diffstat (limited to 'src/mscorlib')
-rw-r--r--src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs
index 34d07c08c4..6b53ba3b64 100644
--- a/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs
+++ b/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs
@@ -292,21 +292,23 @@ namespace System.Runtime.Loader
{
get
{
- while (m_DefaultAssemblyLoadContext == null)
+ if (s_DefaultAssemblyLoadContext == null)
{
// Try to initialize the default assembly load context with apppath one if we are allowed to
if (AssemblyLoadContext.CanUseAppPathAssemblyLoadContextInCurrentDomain())
{
-#pragma warning disable 0420
- Interlocked.CompareExchange(ref m_DefaultAssemblyLoadContext, new AppPathAssemblyLoadContext(), null);
- break;
-#pragma warning restore 0420
+ // Synchronize access to initializing Default ALC
+ lock(s_initLock)
+ {
+ if (s_DefaultAssemblyLoadContext == null)
+ {
+ s_DefaultAssemblyLoadContext = new AppPathAssemblyLoadContext();
+ }
+ }
}
- // Otherwise, need to yield to other thread to finish the initialization
- Thread.Yield();
}
- return m_DefaultAssemblyLoadContext;
+ return s_DefaultAssemblyLoadContext;
}
}
@@ -329,7 +331,7 @@ namespace System.Runtime.Loader
}
// Update the managed side as well.
- m_DefaultAssemblyLoadContext = context;
+ s_DefaultAssemblyLoadContext = context;
}
// This call opens and closes the file, but does not add the
@@ -412,7 +414,10 @@ namespace System.Runtime.Loader
// Each AppDomain contains the reference to its AssemblyLoadContext instance, if one is
// specified by the host. By having the field as a static, we are
// making it an AppDomain-wide field.
- private static volatile AssemblyLoadContext m_DefaultAssemblyLoadContext;
+ private static volatile AssemblyLoadContext s_DefaultAssemblyLoadContext;
+
+ // Synchronization primitive for controlling initialization of Default load context
+ private static readonly object s_initLock = new Object();
}
[System.Security.SecuritySafeCritical]