Beispiel #1
0
        public static void Setup()
        {
            if (isSetup)
            {
                return;
            }
            for (int i = 0; i < workerAmount; i++)
            {
                workers[i] = new JobWorker();
                Thread thread = new Thread(workers[i].Run);
                workers[i].thread   = thread;
                thread.IsBackground = true;
                thread.Name         = "JobWorker" + i.ToString();
                thread.Priority     = ThreadPriority.Normal;
                thread.Start();
            }

            isSetup = true;
        }
Beispiel #2
0
 internal static bool TryStealWork()
 {
     for (int i = 0; i < workerAmount; i++)
     {
         JobWorker stealTarget = workers[i];
         if (stealTarget.jobIds.TryDequeue(out var jobHandle))
         {
             while (!CanExecuteGroup(jobHandle.group))
             {
                 Thread.Sleep(0);
             }
             if (jobHandle.executor.ExecuteJob(jobHandle))
             {
                 SignalComplete(jobHandle);
             }
             return(true);
         }
     }
     return(false);
 }