internal void StartTask(bool newThread) { if (cancelled) { ThrowCancelException(); } if (TryReserve()) { parent = Task.CurrentTask; if (parent != null) { // register at our parent-task parent.RegisterChild(this); } if (newThread) { JibuThreadPool.runTask(RunTask); } else { TaskScheduler curTaskScheduler = TaskScheduler.CurrentTaskScheduler; if (curTaskScheduler == null) { ThreadScheduler.AddTask(this); } else { curTaskScheduler.QueuedTasks.Push(this); } } } }
internal void Start() { thread = Thread.CurrentThread; CurrentTaskScheduler = this; while (!stopRequested) { Task w = queuedTasks.Pop(); if (w == null) { TaskScheduler other = next; while (other != this) { w = other.Steal(); if (w != null) { break; } other = other.next; } if (w == null) { if (!ThreadScheduler.StealDeque(this)) { stopped = true; CurrentTaskScheduler = null; return; } else { continue; } } } // w should not be null at this point w.RunTask(); } // end while(!stopRequested) // we have been stopped ThreadScheduler.AddTasks(queuedTasks); stopped = true; CurrentTaskScheduler = null; }