Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 C. Use the atomic compare_and_swap instruction to fix the race condition in Problem A.

a. Write a C statement to declare and initialize a shared variable lockTop, whose value is -1 when unlocked and 0 when locked

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

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

d. Does this solution satisfy the mutual-exclusion requirement? Does it satisfy the bounded-waiting requirement?

Just problem C

image text in transcribed

compare and swap Instruction Definition: int compare_and swap (int *value, int expected, int new_value) ( int temp - *value; if (*value expected) *value new_value; return temp; 1. Executed atomically 2. Returns the original value of passed parameter "value" 3. Set the variable "value" the value of the passed parameter "new_value" but only if "value"expected". That is, the swap takes place only under this condition. Operating System Concepts-10th Edition 3.18 Silberschatz, Galvin and Gagne 2018 compare and swap Instruction Definition: int compare_and swap (int *value, int expected, int new_value) ( int temp - *value; if (*value expected) *value new_value; return temp; 1. Executed atomically 2. Returns the original value of passed parameter "value" 3. Set the variable "value" the value of the passed parameter "new_value" but only if "value"expected". That is, the swap takes place only under this condition. Operating System Concepts-10th Edition 3.18 Silberschatz, Galvin and Gagne 2018

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_2

Step: 3

blur-text-image_3

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago