School of Computing Queen's University QUEENA COMPUTING CISC324: Operating Systems Lab 3 Deadline: Friday, Oct. 31, 2022, at 11:59 PM Instructor: Dr. Anwar Hossain Fall 2022 SAPIENTIA ET DOCTRINA STABILITAS ..
Toolbox This lab may be your first time programming exercise in which you will be writing concurrent programs that use semaphores in Java. Java provides you with a package java. util. concurrent. semaphore, in order to use semaphore operations. You will learn how to create and initiate semaphores and use them in both styles: process execution ordering (waiting style) or for critical section (mutual exclusion style). You will also learn how to use the primitives acquire () and release () that have been discussed in the lecture. This lab has been prepared to be conducted on any operating system that runs the Java Virtual Machine. Please make sure to have a well set up environ- ment. You need a computer, an operating system, a Java Virtual Machine, and optionally a Java IDE (e.g., Eclipse). Background and Outcomes In this lab, you are asked to understand and execute the Java code which is provided to you. This Java code is an implementation for the readers and writers classical synchronization problem with readers having priority. The readers and writers are basically implemented by their respective threads. In the readers and writers problem, a shared data structure, usually a file or a database, is accessed by reader threads and writer threads. For efficiency, many readers should be allowed to read simultaneously. For correctness, only one writer is allowed to write into the data structure at a time, all other threads (readers and writers) must wait. There exists three possible solutions. Each solution defines a kind of scheduling policy to decide which thread should first have access to the data structure as described below: · Readers have priority. Once a reader has started reading, all newly- arriving readers are allowed to start reading (multiple readers can read at a time). A waiting writer must wait until all readers have finished. This means that a starvation may occur in cases where there is a steady stream of newly-arriving readers. You have been given the Java code that implements this solution: MainMethod. java: Main Java class that creates reader and writer threads. Reader . java: Reader Java class that defines the reader thread. Writer. java: Writer Java class that defines the writer thread. Synch. java: This Java class declares the semaphores (mutex and wrt) and counter (readcount) used to synchronize readers and writers. RandomSleep. java: This Java class defines a <doSleep= method for suspending a thread. · Writers have priority. Anytime there is a writer waiting, no new readers are allowed to start. In case there is a steady stream of newly-arriving writers, the readers may starve. 1
· A starvation-free solution. To avoid starvation it is necessary for readers to give priority to writers, and vice versa. In a busy system, this results in one batch of readers, followed by one writer, followed by