This exercise will allow us to implement some of the basic IPC mechanisms that are described within Chapter 6 of the text. Be sure that you are clear on what mutual exclusion and synchronization are and the various design issues such as race conditions, and busy waiting that some IPC algorithms have to face.
Refer to the attached ipc.java file. This file contains an implementation of a class Process. In this implementation, class Process does not support mutual exclusion (i.e., Processes may be inside their critical regions at the same time.) Modify the implementation of class Process so that it tries to achieve mutual exclusion using one of the following methods: (1) Plain lock variable, (2) Peterson's solution, or (3) a binary Semaphore object.
Hints:
(1) Plain locks and Peterson's protocols are discussed in Chapter 6 of the text.
(2) Binary semaphores are discussed in Chapter 6 of the text.
(3) The Java statement private static int lock;, when used to declare a data member of a given class, tells Java that the data member will be shared by all of the instances of the class, so using this statement to make lock a static data member of class Process will ensure that all of the Process objects created within the main() method will have Read/Write access to the same copy of lock.)
Run your final program several times and analyze its output.
Questions:
Your Process.run() method correctly implements the pre-entry protocol of the algorithm that you are using (plain lock, peterson, binary semaphore). Identify the places within your code where this can be seen.
Your Process.run() method correctly implements the post-exit protocol of the algorithm that you are using (plain lock, peterson, binary semaphore). Identify the places within your code where this can be seen.
Can a race condition occur with your solution (one process is running critical before the other process has exited it)? Why or why not?
Can a starvation condition occur with your solution (e.g., one process never gets to run critical())? Why or why not?
Can busy waiting occur anywhere in your solution (e.g., one process repeatedly asking the CPU to check whether it can now run critical())? Why or why not?
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.