Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 2 3 4 5 class TwoThreadLockFreeQueue { = int head 0, tail = 0; TO] items; public TwoThreadLockFreeQueue (int capacity) { head 0;

image text in transcribed

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

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

The Core Ios Developer S Cookbook Core Recipes For Programmers

Authors: Erica Sadun ,Rich Wardwell

5th Edition

0321948106, 978-0321948106

More Books

Students also viewed these Programming questions