Question
Question 1: The following Java code samples describe a Lock class with two methods: acquire() and release(). You can assume that the application calls lock.acquire()
Question 1:
The following Java code samples describe a Lock class with two methods: acquire() and release(). You can assume that the application calls lock.acquire() before entering a critical section and lock.release() after exiting the critical section.
For the implementations that require a tid (i.e., thread id), you can assume that the tid of each thread is either 0 or 1.
Hint: Remember to consider how variables are initialized! For each segment of code sample given below (each box represents a code segment), answer the following questions and justify your answer by providing appropriate arguments:
1. Does the code guarantee mutual exclusion?
2. Does the code guarantee progress?
3. List all other limitations that exist for each implementation. Issues you might consider include (but are not limited to) the following: generality, efficiency, and fairness. (Note: You
can skip this part of the question when the implementation fails to provide mutual exclusion or progress.)
class Lock [ private int turn -0 public void acquire (int tid) ( while (turn- (1- tid)) public void release (int tid) [ turn = (1 - tid); class Lock [ private int turn-0 private boolean lock [2-false, false public void acquire (int tid) ( lock[tid] true; turn = 1 - tid; while (lock[1-tid] &&turn tid)); public void release (int tid) [ lock[tid] -false; class Lock [ public void acquire) ( disableInterrupts) public void release) enableInterrupts) class Lock [ private boolean lock - true; public void acquire) ( public void release) while (TestAndSet (lock, true); lock false
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started