Consider the problem of implementing a bounded stack using an array indexed by at op counter, initially zero. In the absence of concurrency, these methodsare almost trivial. To push an item, increment...

Consider the problem of implementing a bounded stack using an array indexed by at op counter, initially zero. In the absence of concurrency, these methodsare almost trivial. To push an item, increment top to reserve an array entry, and then store the item at that index. To pop an item, decrement top, and return the item at the previous top index. Clearly, this strategy does not work for concurrent implementations, because one cannot make atomic changes to multiple memory locations. A single synchronization operation can either increment or decrement the top counter, but not both, and there is no way atomically to increment the counter and store a value. Never the less, Bob D. Hacker decides to solve this problem. He decides to adapt the dual data structure approach of Chapter10 to implement a dual stack. His Dual Stack class splits push ()and pop()methods into reservation and fulfillment steps. Bob’s implementation appears in The stack’s top is indexed by the top field, an Atomic Integer manipulated only by get And Increment() and get And Decrement()calls. Bob’s push ()method’s reservation step reserves a slot by applying get And Increment ()to top. Suppose the call returns?




Jan 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here