コード例 #1
0
    private void InitThreadPool()
    {
        //--------------- Cap the number of threads --------------------
        int maxThreads = ThreadingMaxThreads;
        if (maxThreads <= 0)
            maxThreads = Mathf.Max(SystemInfo.processorCount - 1, 1);
        //--------------- Cap the number of threads --------------------

        //--------------- Spread the Flocks over multiple worker-packages --------------------
        int ThreadingPoolPackages = ThreadingPackagesPerThread * maxThreads;

        int flocksPerBlock = Mathf.CeilToInt((float)FlockingSpawnCount / (float)ThreadingPoolPackages);
        workerObjects = new FlockingDataWorker[ThreadingPoolPackages];

        int i = ThreadingPoolPackages;
        int startIdx = 0;
        while (--i > -1)
        {
            FlockingDataWorker workerBlock = new FlockingDataWorker();
            UpdateWorkerObjectStats(workerBlock);

            workerBlock.startWorkIndex = startIdx;
            workerBlock.endWorkIndex = Mathf.Min(flockers.Length, startIdx + flocksPerBlock);
            workerObjects[i] = workerBlock;
            startIdx += flocksPerBlock;
        }
        //--------------- Spread the Flocks over multiple worker-packages --------------------

        myThreadScheduler = Loom.CreateThreadPoolScheduler();
        myThreadScheduler.ForceToMainThread = !MultithreadingEnabled;
        myThreadScheduler.StartASyncThreads(workerObjects, onThreadWorkComplete, null, maxThreads);
    }
コード例 #2
0
    void Awake()
    {
        Application.targetFrameRate = 25;
        myThreadScheduler = Loom.CreateThreadPoolScheduler();

        //--------------- Ending Single threaded routine --------------------
        threadA = Loom.StartSingleThread(EndingSingleThreadCoroutine, System.Threading.ThreadPriority.Normal, true);
        //--------------- Ending Single threaded routine --------------------

        //--------------- Continues Single threaded routine --------------------
        threadB = Loom.StartSingleThread(ContinuesSingleThreadCoroutine, System.Threading.ThreadPriority.Normal, true);
        //--------------- Continues Single threaded routine --------------------

        //--------------- Start Multithreaded packages --------------------
        int i = TestWorkerObjects;
        IThreadWorkerObject[] workerObjects = new IThreadWorkerObject[TestWorkerObjects];

        while (--i > -1)
            workerObjects[i] = new LotsOfNumbers(UnityEngine.Random.Range(minCalculations, maxCalculations));

        myThreadScheduler.StartASyncThreads(workerObjects, OnThreadWorkComplete, OnWorkerObjectDone, maxThreads);
        StartCoroutine(AbortAllThreadsAfterDelay());
        //--------------- Start Multithreaded packages --------------------
    }