Esempio n. 1
0
        /// <summary>
        /// Creates a new instance of the TaskDistributor.
        /// </summary>
        /// <param name="workerThreadCount">The number of worker threads, a value below one will create ProcessorCount x3 worker threads.</param>
        /// <param name="autoStart">Should the instance auto start the worker threads.</param>
        public TaskDistributor(int workerThreadCount, bool autoStart)
        {
            if (workerThreadCount <= 0)
            {
                                #if !NO_UNITY
                workerThreadCount = UnityEngine.SystemInfo.processorCount * 3;
                                #else
                workerThreadCount = Environment.ProcessorCount * 3;
                                #endif
            }

            workerThreads = new TaskWorker[workerThreadCount];
            lock (workerThreads)
            {
                for (var i = 0; i < workerThreadCount; ++i)
                {
                    workerThreads[i] = new TaskWorker(this);
                }
            }

            if (mainTaskDistributor == null)
            {
                mainTaskDistributor = this;
            }

            if (autoStart)
            {
                Start();
            }
        }
        /// <summary>
        /// Creates a new instance of the TaskDistributor.
        /// </summary>
        /// <param name="workerThreadCount">The number of worker threads, a value below one will create ProcessorCount x3 worker threads.</param>
        /// <param name="autoStart">Should the instance auto start the worker threads.</param>
        public TaskDistributor(int workerThreadCount, bool autoStart)
        {
            if (workerThreadCount <= 0)
            {
                #if !NO_UNITY
                workerThreadCount = UnityEngine.SystemInfo.processorCount * 3;
                #else
                workerThreadCount = Environment.ProcessorCount * 3;
                #endif
            }

            workerThreads = new TaskWorker[workerThreadCount];
            lock (workerThreads)
            {
                for (var i = 0; i < workerThreadCount; ++i)
                    workerThreads[i] = new TaskWorker(this);
            }

            if (mainTaskDistributor == null)
                mainTaskDistributor = this;

            if (autoStart)
                Start();
        }