Beispiel #1
0
        /// <summary>
        /// Removes and signals all waiting threads, invokes done(), and
        /// nulls out callable.
        /// </summary>
        private void FinishCompletion()
        {
            // assert state > COMPLETING;
            for (WaitNode q; (q = Waiters) != null;)
            {
                if (UNSAFE.compareAndSwapObject(this, WaitersOffset, q, null))
                {
                    for (;;)
                    {
                        Thread t = q.thread;
                        if (t != null)
                        {
                            q.thread = null;
                            LockSupport.Unpark(t);
                        }
                        WaitNode next = q.next;
                        if (next == null)
                        {
                            break;
                        }
                        q.next = null;                         // unlink to help gc
                        q      = next;
                    }
                    break;
                }
            }

            Done();

            Callable = null;             // to reduce footprint
        }