Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the unbounded queue implementation shown in Fig. 10.21. This queue is blocking, meaning that the deq () method does not return until it has

Consider the unbounded queue implementation shown in Fig. 10.21. This queue is blocking, meaning that the deq () method does not return until it has found an item to dequeu

image  

The queue has two fields: items is a very large array, and tail is the index of the next unused element in the array.

1. Are the enq () and deq () methods wait-free? If not, are they lock-free? Explain.

2. Identify the linearization points for enq () and deq(). (Careful! They may be execution-dependent.)



1 public class HWQueue ( 2 AtomicReference [] items; Atomic Integer tail; 3 4 5 6 7 public void enq (T x) { int i = tail.getAnd Increment (); items [1].set(x); } public T deq () ( while (true) { int range tail.get(); for (int i = 0; i < range; i++) { T value items [1].getAndSet (null); if (value != null) { return value; 8 9 10 11 12 13 14 15 16 17 18. 19 20 } Figure 10.21 Queue used in Exercise 125.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Lets analyze the provided queue implementation Waitfree or lockfree The enq method increments the ta... 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

Visual C# How to Program

Authors: Paul J. Deitel, Harvey Deitel

6th edition

134601548, 134601793, 978-0134601540

More Books

Students also viewed these Programming questions