Question: Problem A. The pseudocode as below illustrates the basic push() and pop() operations of an array-based stack, where top is initialized as 0 when the

Problem A. The pseudocode as below illustrates the basic push() and pop() operations of an array-based stack, where top is initialized as 0 when the stack is empty. Assuming that at a given moment, SIZE is equal to 20, top is equal to 8, this code is used in a concurrent environment (top and stack[] are in shared memory section), process P0 is about to call push() and process P1 is about to call pop() concurrently.

push(item) {

if (top

stack[top] = item; // LINE A

top++; // LINE B }

else ERROR }

pop() {

if (top > 0) {

top--; // LINE X

return stack[top]; // LINE Y }

else ERROR }

Problem B. Use the atomic test_and_set instruction to fix the race condition in Problem A.

a. Write C statement(s) to declare and initialize a shared variable lockTop

b. Re-write the push() function to call the test_and_set() function defined in the PPT Slide 3.16 for Section III

c. Re-write the pop() function to call the test_and_set() function defined in the PPT Slide 3.16 for Section III

Just Problem BProblem A. The pseudocode as below illustrates the basic push() and pop()

test and set Instruction Definition: boolean test_and set (boolean *target) boolean rv - *target; *targetTRUE; return rv: 1. Executed atomically 2. Returns the original value of passed parameter 3. Set the new value of passed parameter to "TRUE" Operating System Concepts-10th Edition 3.16 Silberschatz, Galvin and Gagne 2018

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 Databases Questions!