コード例 #1
0
        public void Judge(List <int> winners, List <TeamResult> teamResults)
        {
            //Queue a command to judge the outcome
            lock (mWorkerThreads)
            {
                //Hand the jobs out to the workers circularly
                ConcurrentQueue <DivisionWinnerCalculatorCommand> queue = mWorkerQueues[mWorkerIndex];
                mWorkerIndex = (mWorkerIndex + 1) % NumWorkerThreads;

                queue.Enqueue(DivisionWinnerCalculatorCommand.CreateJudgeCommand(winners, teamResults));
            }
        }
コード例 #2
0
        public void FinishSession(Action <int, List <int> > finishedCallback)
        {
            lock (mWorkerThreads)
            {
                //Tell all the workers to finish
                foreach (ConcurrentQueue <DivisionWinnerCalculatorCommand> queue in mWorkerQueues)
                {
                    queue.Enqueue(DivisionWinnerCalculatorCommand.CreateFinishSessionCommand());
                }

                //Wait for the worker threads to join
                foreach (Thread thread in mWorkerThreads)
                {
                    thread.Join();
                }

                mWorkerQueues.Clear();
                mWorkerThreads.Clear();
            }

            EndTime = DateTime.Now;

            finishedCallback?.Invoke(-1, null);
        }