Beispiel #1
0
        static int RunMultiCore()
        {
            // While there are programs in the job queue
            while (Queue.New.First != null)
            {
                // Load to memory from disk - requires the mmu lock to access
                LongTermScheduler.Execute();

                // While the ready queue is not empty thread the CPU threads
                while (Queue.Ready.First != null)
                {
                    // Dispatch to CPUs
                    ShortTermScheduler.Start();

                    foreach (var core in Cores)
                    {
                        if (!core.isWaiting && core.ActiveProgram != null)
                        {
                            // Wait for the core thread to start and the CPU acquires the MMU lock in its critical section
                            System.Console.WriteLine("Running PCB: " + core.ActiveProgram.ProcessID);
                            core.Run();
                        }
                    }
                }
            }

            if (Queue.Terminated.Count != 30 || Queue.New.First != null)
            {
                return(-1);
            }

            return(0);
        }
        /// <summary>
        /// Acquires the queue lock for the new queue and validates the new queue is not empty
        /// --> Make async if Queue lock
        /// </summary>
        static void __init()
        {
            // For single core priority since the MMU only gets loaded one program at a time, need to select based on priority
            if (degree == 0 && ShortTermScheduler.POLICY == SchedulerPolicy.Priority)
            {
                Driver._QueueLock.Wait();
                var toSort = Queue.New;
                Queue.New = ShortTermScheduler.InsertSort(toSort);
                Driver._QueueLock.Release();
                degree = 1;
            }

            if (Driver._QueueLock.CurrentCount != 0)
            {
                if (Queue.New.First != null)
                {
                    currentPointer = Queue.New.First.Value;
                }
            }
        }
Beispiel #3
0
        static int RunSingleCore()
        {
            while (Queue.New.First != null)
            {
                // Acquires the mmu semaphore for reading and writing to memory
                LongTermScheduler.Execute();
                ShortTermScheduler.Start();

                // Waits for the core thread to run
                System.Console.WriteLine("Running PCB: " + Cores[0].ActiveProgram.ProcessID);
                Cores[0].Run();
                // WriteToFile("ramdata", RAMDUMP());
            }

            if (Queue.Terminated.Count != 30 || Queue.New.First != null)
            {
                return(-1);
            }

            return(0);
        }