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

 Problem A. The pseudocode as below illustrates the basic pushO and

Problem A. The pseudocode as below illustrates the basic pushO and pop0 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 PO is about to call push0 and process P1 is about to call pop0 concurrently a. Which variable has a race condition? What are the items on stack when top is equal to 8 (hint: stack[0], stack[1]..., stack[??2]. b. In which order LINES A, B, X, and Y are executed such that an item is correctly pushed onto the stack as stack [i] by P0 first and then popped out by P1? What is the value of i? What is the value of top when PO is done with pushing? What is the value of top when P1 is done with popping? c. In which order LINES A, B, X, and Y are executed such that an item stack j] is correctly popped out of the stack by P1 first and then PO pushes an item onto the stack as stack[k]? What are the values ofj and k? What is the value of top when P1 is done with popping? What is the value of top when PO is done with pushing? d. In which order LINES A, B, X, and Y are executed such that P0 adds an item onto the stack as stack [8] first, then P1 reads stack[7], finally top still remains as 8 after both PO and P1 are done? This is a case where PO's push operation is voided. e. In which order LINES A, B, X, and Y are executed such that PO first incorrectly replaced the original item stack[7] on stack with its new item, then P1 reads stack [8] with a random value, finally top still remains as 8 after both PO and P1 are done? This is a case where P1's pop operation is voided. push (item) if (top SIZE) I stack[top] item; top++; // LINE A // LINE B else ERRO pop ) if (top > 0) top return stack[top] // LINE x // LINE Y else ERROR

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!