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