Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

=+d. Is there another print vehicle you would suggest?

Answered: 1 week ago