diff options
author | Marek Safar <marek.safar@gmail.com> | 2014-01-10 17:38:35 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2014-01-10 17:38:35 +0400 |
commit | 75bc8d1e1d37b2aede78a51aac73ce73089ab947 (patch) | |
tree | 8c4f48039bdf6634b2260bb33a7c0dc486eaf061 /mcs | |
parent | c67aed9a47333b80732cf74c8cb28f247d9edec9 (diff) |
[corlib] Hunting down rare Task.WaitAll race
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/corlib/System.Threading.Tasks/TaskContinuation.cs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/mcs/class/corlib/System.Threading.Tasks/TaskContinuation.cs b/mcs/class/corlib/System.Threading.Tasks/TaskContinuation.cs index e5906be5a5b..12eaa8be194 100644 --- a/mcs/class/corlib/System.Threading.Tasks/TaskContinuation.cs +++ b/mcs/class/corlib/System.Threading.Tasks/TaskContinuation.cs @@ -339,6 +339,7 @@ namespace System.Threading.Tasks sealed class CountdownContinuation : IContinuation, IDisposable { readonly CountdownEvent evt; + bool disposed; public CountdownContinuation (int initialCount) { @@ -353,12 +354,18 @@ namespace System.Threading.Tasks public void Dispose () { + disposed = true; + Thread.MemoryBarrier (); + evt.Dispose (); } public void Execute () { - evt.Signal (); + // Guard against possible race when continuation is disposed and some tasks may still + // execute it (removal was late and the execution is slower than the Dispose thread) + if (!disposed) + evt.Signal (); } } |