CPU Scheduler

Implemenenting a Doubly-Linked Circular List

Project Due: 11:59 PM Tuesday, July 2

1.0 Objective

In this project you will learn to insert and delete items from a doubly-linked circular list. You will also learn to work with interfaces. Don't panic! It is not as bad as it sounds - unless it sounds really easy, then it's worse than it sounds.

2.0 Project Description

2.1 CPU Scheduler
In modern computer systems, it is common for users to have many programs running at one time. One of the most basic functions of an operating system is to schedule these processes. This process can actually become quite involved. For this project, we will assume a very simple round-robin scheduler. This simply means that each process gets to run for a set amount of time. If the process does not finish, it goes to the end of the line and the next process gets to run. This policy is very fair and very easy to implement.
One of the best ways to implement this policy is through the use of a doubly-linked circular list. Any new job is added to the "back" of the list (the spot directly proceeding the job currently being run). Whenever a job finishes, it is simply removed from the list. If a job does not finish in its allotted time, it is moved to the "back" of the list (this is done by simply moving the current reference ahead in the list by one node). To make this more clear, the following three diagrams show what happens for each of the above cases.

All of the code for the CPU scheduler has been provided for you as well as an interface that describes all of the functions your list will have to implement (see Section 3.0 - Provided Code). You are responsible for generating the class that represents a node in your list (more on this later).

To run the scheduler, you must first download the provided scheduler code (section 3.0), implement your list, and then compile it all. To run the program you type the following at the command prompt:

prompt> java Scheduler testFile

You should replace testFile with the actual name of a testing file. The only one currently provided for you is test-1.dat. The format of this file is not really important but for the curious minded out there I will include a quick description of it. Each line consists of three fields. The first is the id of the process, the second is the arrival time of the process to the CPU, and the last entry is the time the process needs to use the CPU for. You do not need to worry at all about how the scheduler works, you just need to be able to interpret its output (of course, you should feel free to look at the scheduler code if you would like to). Section 5.0 - Grading, will give more details on how to validate the output of the scheduler.

2.2 List Implementation
You will need to create two classes for this project. One called DoubleCircularList, and the other called DoubleNode. You must give them these two names. The DoubleNode class is used to represent a single node in your list. Its design and implementation are entirely up to you. It will only be referenced by the methods in your DoubleCircularList class. It should contain at least the following fields (and provide a means of accessing these fields):

The DoubleCircularList class must implement the DCListOps.java interface. This interface contains all of the linked list methods that the round-robin scheduler will call. How you implement these methods is entirely up to you, but it must maintain a doubly linked, circular list. If you would like to include other methods besides those listed in the interface, that is perfectly fine. However, you will only be graded on your implementation of all the methods in the DCListOps interface.

The following is a brief description of all the methods you must implement:

Method Description
void add(Object item); Places a new object at the end of the list. The end of the list is defined as the node immidiately preceeding the current node.
Object removeCurrent(); Removes the current node, moves the current pointer to the next node, and returns a reference to the recently removed node. If the list is empty, this should return null. If there is only one item in the list, it should be removed and current should refer to null.
void next(); Simply moves the current pointer to the next object in the list. If there is only one item in the list or the list is empty, nothing happens.
Object getCurrent(); Returns a reference to the current node. It does not remove the node from the list or move the current pointer. If the list is empty, null is returned.
boolean isEmpty(); Returns true if the list is empty, false otherwise.
void printList(); Goes through every node in the list, retrieves the data stored in the node, and calls the data's toString() method. It should always start with the current node and end with the last node in the list (thus, the ordering will change depending on where the current reference is). If the list is empty, nothing should get printed. This method should contain a line that looks something like this (it does not have to look exactly like this):

System.out.println(tmp.getData().toString());

This line should obviously be in some type of a loop.

3.0 Provided Code

To download the following code, simply right click on the link and do a Save As on the link. If you have any problems downloading this code, please let me know right away.

4.0 Handing in Your Project

The directory for handing in your program can be found at:

/p/course/cs537-mattmcc/public/username/p1

You should submit all *.java files that you created that are needed to compile your program. You should not submit any *.class files or any of the files we provided for you.

Also, be sure to comment your code well so that it can be easily browsed to see what is going on. Code that is excessively difficult to read will be penalized.

5.0 Grading

The project is due at 11:59 PM on Tuesday, July 2. NO LATE ASSIGNMENTS WILL BE ACCEPTED! The project will be graded out of 100 points and be graded on the following criteria:

All grading will be done on the Novas. This does not mean you have to do your project on a Nova, but if you use some other machine, make sure it works on a Nova before handing it in.

We will grade your code by running it against a series of test files and checking the output of the scheduler against a known, correct implementation. Any differences in your output versus that of the correct implementation will result in a point deduction. Currently, the only test file provided is test-1.dat. We have also provided the correct results for that test. More tests may (or may not) be provided for you in the coming week. Without a doubt, much more in depth tests will be run than this initial one provided. This means you should right some of your own test files and check for any errors.

We will also examine parts of your code to make sure that you are implementing the data structures as required. For example, we may go through the removeCurrent() method to make sure you are doing all the things that are consistant with a doubly-linked, circular list. If you are getting the correct results but doing it by implementing a singly-linked list, your score will suffer severely. You must implement the proper data structure.