Example #1
0
 private async Task <int> AllocateLotteryTickets()
 {
     //Random r = new Random((int) (seed << 32));
     foreach (SimulatorProcess process in readyQueue)
     {
         for (int i = 0; i < (10 - process.ProcessPriority); i++)
         {
             LotteryTicket ticket = new LotteryTicket(issuedLotteryTickets.Count, process, 1);
             issuedLotteryTickets.Add(ticket);
         }
     }
     return(0);
 }
Example #2
0
        private async Task <int> DrawLottery(int ticketNumber)
        {
            LotteryTicket ticket = issuedLotteryTickets.Where(x => x.Id == ticketNumber).FirstOrDefault();

            if (ticket == null)
            {
                return(0);
            }
            while (runningProcess != ticket.Owner)
            {
                if (runningProcess != null && !runningProcess.Unit.Done)
                {
                    readyQueue.Enqueue(runningProcess);
                    runningProcess = null;
                }
                System.Console.WriteLine("Items in Queue: " + readyQueue.Count);
                runningProcess = readyQueue.Dequeue();
            }
            return(0);
        }