Question: class FastPath implements Lock { private static ThreadLocal myIndex; private Lock lock; private int x, y = 1; public void lock() { int i =

class FastPath implements Lock {

private static ThreadLocal myIndex;

private Lock lock;

private int x, y = 1;

public void lock() {

int i = myIndex.get();

x = i; // Im here

while (y != 1) {} // is the lock free?

y = i; // me again?

if (x != i) // Am I still here?

lock.lock(); // slow path

}

public void unlock() {

y = 1;

lock.unlock();

}

}

Figure 2: Fast path mutual exclusion algorithm.(Figure 2 is the above code) In practice, almost all lock acquisitions are uncontended, so the most practical measure of a locks performance is the number of steps needed for a thread to acquire a lock when no other thread is concurrently trying to acquire the lock. Scientists at Cantaloupe-Melon University have devised the following wrapper for an arbitrary lock, shown in Fig. 2. They claim that if the base Lock class provides mutual exclusion and is starvation-free, so does the FastPath lock, but it can be acquired in a constant number of steps when uncontended. Sketch an argument why they are right, or give a counterexample.

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!