Answered step by step
Verified Expert Solution
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.
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
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