Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 2 3 4 5 class TwoThreadLockFreeQueue { = int head 0, tail = 0; TO] items; public TwoThreadLockFreeQueue (int capacity) { head 0;
1 2 3 4 5 class TwoThreadLockFreeQueue { = int head 0, tail = 0; TO] items; public TwoThreadLockFreeQueue (int capacity) { head 0; tail = 0; items (T) new Object [capacity]; public void enq(Tx) { 6 7 } 8 9 10 11 12 } 13 14 15 16 17 while (tailhead == items.length) {}; items [tail items.length] = x; tail++; public Object deq() { while (tail -head == 0) {}; Object x = items [head & items.length]; head++; return x; 18 19 } } Figure 10.20 A Lock-free FIFO queue with blocking semantics for a single enqueuer and single dequeuer. The queue is implemented in an array. Initially the head and tail fields are equal and the queue is empty. If the head and tail differ by capacity, then the queue is full. The enq() method reads the head field, and if the queue is full, it repeatedly checks the head until the queue is no longer full. It then stores the object in the array, and increments the tail field. The deq() method works in a symmetric way.
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