Question: 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,

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!