Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fig. 7.33 shows an alternative implementation of CLHLock in which a thread reuses its own node instead of its predecessor node. Explain how this implementation

Fig. 7.33 shows an alternative implementation of CLHLock in which a thread reuses its own node instead of its predecessor node. Explain how this implementation can go wrong.


image

2 1 public class BadCLH Lock implements Lock { // most recent lock holder AtomicReference tail; // thread-local variable ThreadLocal myNode; public void lock () { Qnode qnode myNode.get(); 3 4 5 6 7 8 9 10 11 12 13 14. 15 16 17 qnode.locked= true; // I'm not done // Make me the new tail, and find my predecessor Qnode pred = tail.getAndSet (qnode); // spin while predecessor holds lock while (pred.locked) {} } public void unlock() { // reuse my node next time myNode.get ().locked = false; } static class Qnode { // Queue node inner class public boolean locked = false; 18 19 20 21 } Figure 7.33 An incorrect attempt to implement a CLHLock. }

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

Data Structures and Algorithms in Java

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

6th edition

1118771334, 1118771338, 978-1118771334

More Books

Students also viewed these Programming questions

Question

Determine io in the circuit of Fig. 2.84. 222 51o 54 V(+

Answered: 1 week ago

Question

What are a VMware components of the VxRail HCI system software?

Answered: 1 week ago