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 -------------------- }
//--------------- Managing a simple single Thread -------------------- //--------------- Managing a simple multithreaded ThreadPoolScheduler implementation -------------------- public void OnWorkerObjectDone(IThreadWorkerObject finishedObj) { LotsOfNumbers fCast = (LotsOfNumbers)finishedObj; Debug.LogWarning("Object done! result: " + fCast.result + ", maxIterations: " + fCast.maxIterations + ", ID: " + Thread.CurrentThread.ManagedThreadId + ", progress: " + (myThreadScheduler.Progress * 100f)); }
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 -------------------- }