Operating System

profileOluwatoyin
OS_Assignment_21.pdf

Operating System - Assignment II Mutex locks and semaphores, as discussed in class, are different techniques to solve the race condition and to ensure an efficient synchronization between cooperating threads and processes. In this assignment, you will use locks and semaphores to solve several synchronization problems between cooperating threads. You can develop the required work either on your computer or on the Ubuntu VM you installed, and you can use any Java IDE you find appropriate (e.g., NetBeans, Eclipse, IntelliJ). Follow the video posted on D2L; in this video, you will create a new Java program and package before you copy a number of .java files to your project. This video shows how to use mutex lock and semaphore between cooperating threads. As discussed and shown in the video, it is important to note that:

• Mutex Lock, in literature, uses acquire() and release(). However, in the standard library of Java, these functions are lock() and unlock(), respectively. The same functionalities but with different names.

• Semaphore, in literature, uses wait() and signal(). However, in the standard library of Java, these functions are acquire() and release(), respectively. The same functionalities but with different names.

Task description:

The files (named question1, question2, and question3) are for three different synchronization problems, with a full Java skeleton. The comments in the Java files explain in detail the required functionalities and guide you to where exactly you should place your implementation, read them carefully before starting coding. DO NOT CHANGE any already existing code (e.g., function name, variable name).

• In the first question, the deposit and withdraw functions share a bank account to add a certain amount or subtract a certain amount from the balance, respectively. Use semaphore(s) to implement the synchronization.

• • In the second question, the producer and consumer functions share an array of integer values to add items

or remove items from the buffer, respectively. Use mutex lock(s) to implement the synchronization. • • In the third question, the Ascending and Descending functions share an array of integer values to sort

them in ascending or descending order, respectively. Use either mutex lock(s) or semaphore(s) to implement the synchronization. Implement the sorting method you find appropriate (e.g., selection sort, bubble sort, insertion sort), but don’t use collection methods/APIs (e.g., Arrays.sort).

Note: the threads running the above questions are implemented to run in an infinite loop, so at some point, you may need to force-stop the program.

Submission:

1. This is an individual assignment -- Cheating/plagiarism will be checked and will receive zero. 2. Your submission to the folder titled Assignment 2 under the D2L Assignments tab contains the following:

a. The three java files you worked on b. One Runtime.pdf: - For each of the three java files, copy the full java code and add a

clear screenshot of the output after running the code. * these are separate files within your submission, don’t submit a zip file

3. The assignment is due October 21st – 11:59pm. You can submit your assignment within 24 hours

after this due date to be graded out of 50% of the assignment’s grade. After this grace period, your late submission will not be accepted.