Пример #1
0
        private PoolWorker GetPoolWorker(int id)
        {
            var poolWorker = new PoolWorker();

            poolWorker.Thread = new Thread(() => AssignJob(poolWorker));
            poolWorker.Name   = $"Worker #{id}";

            return(poolWorker);
        }
Пример #2
0
        private void AssignJob(PoolWorker poolWorker)
        {
            poolWorker.IsSpawned = true;
            SendWorkerToSleep(poolWorker);

            while (poolWorker.SleepUntilJob(_cancellationToken))
            {
                DoJob();
                SignalJobQueueStatus();

                poolWorker.SendToSleep();
                SendWorkerToSleep(poolWorker);
            }
        }
Пример #3
0
 private void SendWorkerToSleep(PoolWorker poolWorker)
 {
     _sleepingStack.Push(poolWorker);
     SignalWorkerAsSleeping();
 }