Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

Describe the six tools required to use HR analytics in a firm.

Answered: 1 week ago