Release continuation ancestor before running. Fixes #15036
authorMarek Safar <marek.safar@gmail.com>
Wed, 9 Oct 2013 08:43:41 +0000 (10:43 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 9 Oct 2013 08:43:41 +0000 (10:43 +0200)
mcs/class/corlib/System.Threading.Tasks/Task.cs

index a0e45439d1f435ef3e13c850b46eccccb02602df..1ae5559957ee710ce4206daf00fb0532f1df6987 100644 (file)
@@ -49,8 +49,8 @@ namespace System.Threading.Tasks
                
                // parent is the outer task in which this task is created
                readonly Task parent;
-               // contAncestor is the Task on which this continuation was setup
-               readonly Task contAncestor;
+               // A reference to a Task on which this continuation is attached to
+               Task contAncestor;
                
                static int          id = -1;
                static readonly TaskFactory defaultFactory = new TaskFactory ();
@@ -500,7 +500,9 @@ namespace System.Threading.Tasks
                void InnerInvoke ()
                {
                        if (IsContinuation) {
-                               invoker.Invoke (contAncestor, state, this);
+                               var ancestor = contAncestor;
+                               contAncestor = null;
+                               invoker.Invoke (ancestor, state, this);
                        } else {
                                invoker.Invoke (this, state, this);
                        }