CS215

Assignment #7 (Fourth Programming Project, First Part)


DUE: Tuesday, 11/18/2014

This project and the next will be a significant extension of the thread scheduler discussed in lecture a while back; the relevant source code is here. The ultimate goal will be to simulate a CPU scheduler with multilevel feedback queues using Java threads.

At this stage, however, we will be concentrating on the fact that the SimpleScheduler project as given just plain doesn't work! At present, the code uses Java thread priorities to simulate the scheduling, in which the scheduler thread yields priority to the running thread, and once (every quantum) the scheduler is supposed to wake up at a higher priority to schedule the next running thread. As we discussed earlier, Java thread priorities are mere suggestions to the implementer, and hence there is no guarantee that this scheme will work. And indeed, it doesn't. In this assignment, you will fix that.

First, notice in the source code that the class CircularList isn't really an honest queue (it's just a list of numbers and we cycle around using an index). This is not the source of the problem, but start by making it a legit queue!

Much more importantly: Using techniques of Java thread synchronization (i.e., synchronized methods or blocks, reentrant locks, semaphores, etc.; the design decisions are up to you), write a program that simulates round-robin scheduling for 3 threads. (Of course it should allow for any number of threads, but for now let's stick to running it with 3.) Allow for varying random CPU bursts for the different threads, so that if the running thread runs to the end of its burst while the scheduler is waiting for the current quantum to run out, the thread will wake the scheduler which will then schedule the next thread. A possible transcript of a simulation is given here.

Where to begin? Begin by studying the source code. Compile and run the four files TestScheduler.java (the main class), Scheduler.java, TestThread.java and CircularList.java. In addition, here is a particular coding exercise to get you started. It's quite likely you'll end up with four source files with the same names, but significantly modified.

Back to CS215 Home Page