public MultiThreadedParallelTaskCollection(int numberOfThreads = MAX_CONCURRENT_TASKS, bool relaxed = false)
        {
            _runners       = new MultiThreadRunner[numberOfThreads];
            _taskRoutines  = new ITaskRoutine[numberOfThreads];
            _parallelTasks = new ParallelTaskCollection[numberOfThreads];

            //prepare a single multithread runner for each group of fiber like task collections
            //number of threads can be less than the number of tasks to run
            for (int i = 0; i < numberOfThreads; i++)
            {
                _runners[i] = new MultiThreadRunner("MultiThreadedParallelTask:".FastConcat(i), relaxed);
            }

            //prepare the fiber-like paralleltasks
            for (int i = 0; i < numberOfThreads; i++)
            {
                var ptask = TaskRunner.Instance.AllocateNewTaskRoutine();
                var ptc   = new ParallelTaskCollection();
                ptc.onComplete += DecrementConcurrentOperationsCounter;

                ptask.SetEnumerator(ptc).SetScheduler(_runners[i]);

                _parallelTasks[i] = ptc;
                _taskRoutines[i]  = ptask;
                //once they are all done, the process will be completed
            }
        }
Exemple #2
0
        //physicScheduler -> updateScheduler -> coroutineScheduler -> lateScheduler

        internal static void KillSchedulers()
        {
            if (_multiThreadScheduler != null && multiThreadScheduler.isKilled == false)
            {
                _multiThreadScheduler.Dispose();
            }
            _multiThreadScheduler = null;

#if UNITY_5 || UNITY_5_3_OR_NEWER
            if (_coroutineScheduler != null)
            {
                _coroutineScheduler.Dispose();
            }
            if (_physicScheduler != null)
            {
                _physicScheduler.Dispose();
            }
            if (_lateScheduler != null)
            {
                _lateScheduler.Dispose();
            }
            if (_updateScheduler != null)
            {
                _updateScheduler.Dispose();
            }

            _coroutineScheduler = null;
            _physicScheduler    = null;
            _lateScheduler      = null;
            _updateScheduler    = null;
#endif
        }
        public MultiThreadParallelTaskCollection(MultiThreadRunner runner) : base()
        {
            _maxConcurrentTasks = uint.MaxValue;
            _taskRoutinePool = new TaskRoutinePool(runner);

            ComputeMaxConcurrentTasks();
        }
Exemple #4
0
 static StandardSchedulers()
 {
     mainThreadScheduler  = new MonoRunner();
     syncScheduler        = new SyncRunner();
     multiThreadScheduler = new MultiThreadRunner();
     physicScheduler      = new PhysicMonoRunner();
 }
Exemple #5
0
        public MultiThreadParallelTaskCollection(MultiThreadRunner runner) : base()
        {
            _maxConcurrentTasks = uint.MaxValue;
            _taskRoutinePool    = new PausableTaskPoolThreadSafe();
            _runner             = runner;

            ComputeMaxConcurrentTasks();
        }
        //physicScheduler -> updateScheduler -> coroutineScheduler -> lateScheduler

        static StandardSchedulers()
        {
            syncScheduler        = new SyncRunner(false);
            multiThreadScheduler = new MultiThreadRunner("MultiThreadRunner", true);
#if UNITY_5 || UNITY_5_3_OR_NEWER
            coroutineScheduler = new CoroutineMonoRunner("StandardCoroutineRunner");
            physicScheduler    = new PhysicMonoRunner("StandardPhysicRunner");
            lateScheduler      = new LateMonoRunner("StandardLateRunner");
            updateScheduler    = new UpdateMonoRunner("StandardMonoRunner");
#endif
        }
        void InitializeThreadsAndData(uint numberOfThreads, bool runningTightTasks)
        {
            _runners       = new MultiThreadRunner[numberOfThreads];
            _taskRoutines  = new ITaskRoutine[numberOfThreads];
            _parallelTasks = new ParallelTaskCollection[numberOfThreads];

            //prepare a single multithread runner for each group of fiber like task collections
            //number of threads can be less than the number of tasks to run
            for (int i = 0; i < numberOfThreads; i++)
            {
                _runners[i] = new MultiThreadRunner("MultiThreadedParallelTask #".FastConcat(i), runningTightTasks);
            }

            Action ptcOnOnComplete = DecrementConcurrentOperationsCounter;
            Func <Exception, bool> ptcOnOnException = (e) =>
            {
                DecrementConcurrentOperationsCounter();
                return(false);
            };


            //prepare the fiber-like paralleltasks
            for (int i = 0; i < numberOfThreads; i++)
            {
                var ptask = TaskRunner.Instance.AllocateNewTaskRoutine();
                var ptc   = new ParallelTaskCollection("ParallelTaskCollection #".FastConcat(i));

                ptc.onComplete  += ptcOnOnComplete;
                ptc.onException += ptcOnOnException;

                ptask.SetEnumerator(ptc).SetScheduler(_runners[i]);

                _parallelTasks[i] = ptc;
                _taskRoutines[i]  = ptask;
            }
        }
 public MultiThreadParallelTaskCollection(MultiThreadRunner runner, uint maxConcurrentTasks)
     : base()
 {
     _maxConcurrentTasks = maxConcurrentTasks;
     _runner = runner;
 }
 public MultiThreadParallelTaskCollection(MultiThreadRunner runner)
     : base()
 {
     _maxConcurrentTasks = uint.MaxValue;
     _runner = runner;
 }
Exemple #10
0
 public MultiThreadParallelTaskCollection(MultiThreadRunner runner, uint maxConcurrentTasks) : this(runner)
 {
     _maxConcurrentTasks = Math.Min(MAX_CONCURRENT_TASK, maxConcurrentTasks);
 }
 public MultiThreadParallelTaskCollection(MultiThreadRunner runner, uint maxConcurrentTasks) : this(runner)
 {
     _maxConcurrentTasks = Math.Min(MAX_CONCURRENT_TASK, _maxConcurrentTasks);
 }