Overview and Objectives
The homework is to write a simple operating system simulation, called 141OS, that applies the programming language mechanisms that support concurrency in Java. 141OS allows multiple users to create, save, and print files, which are stored on multiple disks and printed to multiple printers–all of which can be considered concurrent processes. The goal of the system is to exploit potential parallelism to keep the relatively slow hardware devices (disks and printers) as busy as possible.
Scenario of Use 141OS is an operating system that manages two types of hardware, Disks and Printers, for many users who can create files, save them to disk, and print them.
Users create and save files. Imagine each user is sitting at a keyboard typing commands. To create and save files, a user gives the command .save fileName. The user gives 141OS the data for the file, one line at a time. 141OS handles reading lines from the user and delivering them to the disk, one line at a time. Frequently, the user has 141OS save the file. The user finally gives an end-of-file signal,.end, to indicate that they’re done with the data in the file. 141OS makes an entry into the DirectoryManager, to keep track of where that file is stored—which disk, which sector it starts at, and how long the file is.
Users print files. A user can request to print copies of the file with the command .print fileName.
The user may print a copy of the file, then a second copy of the file, repeating print requests over and over again. For every single print job request, 141OS spawns a new print job thread, to read only one line of the file at a time from the disk and then print that line on a printer, repeating those two actions until the file is completely printed. Each of those actions takes a long time, because only one line can be read at a time, and then only one line can be printed at a time. Each print job thread is allowed only one buffer, a Java Class StringBuffer for reading from the disk. So it takes quite a while to actually print the lines that are inside each file.
141OS manages Disks and Printers. 141OS must ensure the integrity of every file, when saving them to Disks or printing them to Printers. It must manage many existing print job threads, when users are creating many files and printing many copies of those files. It must therefore manage access to the disk and access to the printers, so that there are no overruns or conflicts between users.
Therefore when printing, 141OS must request exclusive access rights to a printer, so that only one job can print at a time. Once granted access to that printer, lines are printed only one at a time,even though there’s a long delay for each line, so that the lines will come out contiguously so that the file is kept intact. If 141OS didn’t synchronize this printing process, there would be a jumbled mess on each printer, with a mix of lines coming from different users’ files but being printed at the same time.
When a file is finished being printed, 141OS releases the exclusive access rights to the printer so that another print job thread can request that printer for printing.
Disks must also be managed as a shared resource. Each user thread is responsible for saving each line of data to the disk. But because there are many threads from many users trying to save fileson a disk, each user thread must request exclusive access rights to the disk in order to save the whole file on the disk. The file lines must be saved contiguously on the disk, so every file has a starting sector and a number of sectors needed. If the file is five lines long, and each line gets saved in one sector, it will take five sectors to store that file. When finished saving an entire file on a disk, 141OS must release the access rights to the disk, so that another user can start writing a file to it.
141OS System Requirements
When 141OS is run from the command line, it is given parameters by the autograder or by your own testing for the number of Users, the number of Disks, and the number of Printers. Disks and Printers are written as classes that simulate hardware devices; thus, functionality cannot be added to them.
Users create files, save them to disk, and print them, according to the following requirements:
- A user must gain access rights to a disk in order to begin writing to it (i.e., to save a file).
- Only one thread is allowed to write to a disk at a time, and that thread must hold access rights to the disk until the file is finished, or else the files will become jumbled.
- Any user’s file can be stored on any disk, and printed by any printer.
- Only one line of a file may be stored in a sector, so a file will require one sector per line.
- Any number of threads can read from a disk at a time, and can be read even when a user is writing to the disk. (This is not normally the case in a real OS, but is simplified to keep the problem within the scope of a homework project.)
- The important goal is to keep all the printers as busy as possible printing files.
The following design diagram shows a system run with 4 Users, 2 Disks, and 3 Printers: