Exemple #1
0
        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);
                    }
                }
            }
        }
Exemple #2
0
        // Instructs the ThreadPool class to run the given Jibu task with the given priority and
        // synchronizing on the provided barrier.
        internal static void runTask(ThreadDelegate task, ThreadPriority priority)
        {
            JibuThread thread = JibuThreadPool.getThread();

            thread.setPriority(priority);
            thread.Task = task;
            thread.runThread();
        }
Exemple #3
0
 // The run method given to the operating system thread to start.
 private void run()
 {
     runevent.WaitOne();
     while (!terminate)
     {
         try
         {
             td();
             JibuThreadPool.freeThread(this);
             runevent.WaitOne();
         }
         catch (System.Exception)
         {
             //This catches both normal user-code caused exceptions and
             //the ThreadAbortException
             terminate = true;
             JibuThreadPool.freeThreadandRelease(this);
             throw;
         }
     }
 }
Exemple #4
0
        private static void CreateTaskScheduler()
        {
            TaskScheduler ts = new TaskScheduler();

            if (last == null) // we have no TaskSchedulers
            {
                last = ts;
                // we make it point to itself
                ts.Next = ts;
            }
            else
            {
                ts.Next   = last.Next;
                last.Next = ts;
                last      = ts;
            }

            if (!queuedTasks.Empty)
            {
                StealDeque(ts);
            }

            JibuThreadPool.runTask(ts.Start);
        }
Exemple #5
0
 /// <summary>
 /// Terminates all free threads in Jibu's thread pool.
 /// </summary>
 /// <remarks>
 /// TerminateFreeThreads releases all idle OS threads in Jibu's internal thread pool.
 /// </remarks>
 // <example>
 // - Manager Example -
 // <code><include ManagerExample/ManagerExample.cs></code>
 // </example>
 public static void TerminateFreeThreads()
 {
     JibuThreadPool.TerminateFreeThreads();
 }
Exemple #6
0
 static ThreadScheduler()
 {
     JibuThreadPool.runTask(Start);
 }