Question: 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

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.)

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

class Lock [ private int turn-0; public void acquire(int tid) t while (turn- (1 - tid) public void release (int tid) f turn = (1 - tid); class Lock ( private int turn = 0; private boolean ock[2] = {false, false); public void acquire(int tid) t lock [tid] = true; turn1 - tid; while (lock[1-tid] && turn-= (1 tid)); - public void release (int tid) ( lock[tid] false; = class Lock f public void acquire) ( disableInterrupts ) public void release () [ enableInterrupts ) class Lock ( private boolean lock -true; public void acquire) l public void release) while (TestAndSet (lock, true) lock- false; class Lock [ private int turn-0; public void acquire(int tid) t while (turn- (1 - tid) public void release (int tid) f turn = (1 - tid); class Lock ( private int turn = 0; private boolean ock[2] = {false, false); public void acquire(int tid) t lock [tid] = true; turn1 - tid; while (lock[1-tid] && turn-= (1 tid)); - public void release (int tid) ( lock[tid] false; = class Lock f public void acquire) ( disableInterrupts ) public void release () [ enableInterrupts ) class Lock ( private boolean lock -true; public void acquire) l public void release) while (TestAndSet (lock, true) lock- false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!