Ejemplo n.º 1
0
        private void FindWork(out Task task)
        {
            bool foundWork = false;

            task = default(Task);

            do
            {
                // check our local queue for work
                if (tasks.LocalPop(ref task))
                {
                    break;
                }

                // check the global queue for work
                if (scheduler.TryGetTask(out task))
                {
                    break;
                }

                /*
                 * // look for any replicable tasks
                 * var replicable = WorkItem.Replicable;
                 * if (replicable.HasValue)
                 * {
                 *  replicable.Value.DoWork();
                 *  WorkItem.SetReplicableNull(replicable);
                 *
                 *  // MartinG@DigitalRune: Continue checking local queue and replicables.
                 *  // No need to steal work yet.
                 *  continue;
                 * }*/

                // try to steal work off other workers
                for (int i = 0; i < scheduler.Workers.Count; i++)
                {
                    var worker = scheduler.Workers[i];
                    if (worker == this)
                    {
                        continue;
                    }

                    if (worker.tasks.TrySteal(ref task))
                    {
                        //they are valid right after create
                        //System.Diagnostics.Debug.Assert(!task.valid);
                        foundWork = true;
                        break;
                    }
                }

                // Wait until a new task gets scheduled.
                if (!foundWork)
                {
                    HasNoWork.Set();
                    Gate.WaitOne();
                    HasNoWork.Reset();
                }
            } while (!foundWork);
        }
Ejemplo n.º 2
0
        private void FindWork(out Task task)
        {
            bool foundWork = false;

            task = default(Task);

            do
            {
                // check our local queue for work
                if (tasks.LocalPop(ref task))
                {
                    break;
                }

                // check the global queue for work
                if (scheduler.TryGetTask(out task))
                {
                    break;
                }

                // look for any replicable tasks
                var replicable = WorkItem.Replicable;
                if (replicable.HasValue)
                {
                    replicable.Value.DoWork();
                    WorkItem.SetReplicableNull(replicable);

                    // MartinG@DigitalRune: Continue checking local queue and replicables.
                    // No need to steal work yet.
                    continue;
                }

                // try to steal work off other workers
                for (int i = 0; i < scheduler.Workers.Count; i++)
                {
                    var worker = scheduler.Workers[i];
                    if (worker == this)
                    {
                        continue;
                    }

                    if (worker.tasks.TrySteal(ref task))
                    {
                        foundWork = true;
                        break;
                    }
                }

                // Wait until a new task gets scheduled.
                if (!foundWork)
                {
                    Gate.WaitOne();
                }
            } while (!foundWork);
        }
Ejemplo n.º 3
0
        private void FindWork()
        {
            LookingForWork = true;
            Task task;
            bool foundWork = false;

            do
            {
                if (scheduler.TryGetTask(out task))
                {
                    foundWork = true;
                    break;
                }

                var replicable = WorkItem.Replicable;
                if (replicable.HasValue)
                {
                    replicable.Value.DoWork();
                    WorkItem.SetReplicableNull(replicable);

                    // MartinG@DigitalRune: Continue checking local queue and replicables.
                    // No need to steal work yet.
                    continue;
                }

                for (int i = 0; i < scheduler.Workers.Count; i++)
                {
                    var worker = scheduler.Workers[i];
                    if (worker == this)
                    {
                        continue;
                    }

                    if (worker.tasks.TrySteal(ref task))
                    {
                        foundWork = true;
                        break;
                    }
                }

                if (!foundWork)
                {
                    // Wait until a new task gets scheduled.
                    Gate.WaitOne();
                }
            } while (!foundWork);

            LookingForWork = false;
            tasks.LocalPush(task);
        }