Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4 - Process Synchronization (a) (10 points) Consider two processes that share a single variables of type Item such that process Po produces an

image text in transcribedimage text in transcribed

Problem 4 - Process Synchronization (a) (10 points) Consider two processes that share a single variables of type Item such that process Po produces an item that is then consumed by process P. (Process' code given side-by-side to conserve space.) // shared variables Item s; // Process PO: // Process P1: // local variable Item il; // local variable Item i2; while (true) while (true) il = CreateItem(); i2 = s; UseItem (12); Show how semaphores can be used to provide the necessary synchronization so that every item produce by Po is consumed exactly once by P, by adding the use of semaphores to the code above. You should assume that Item assignment is an atomic operation. (Note: the space provided is not necessarily indicative of where code should be added.) (b) (10 points) Consider the same problem as in part (a) where Item s is enclosed in a monitor with entry procedures Settem and GetItem that allow processes to set and get s, respectively. Add code below to use condition variables so that the monitor provides the necessary synchronization to ensure every item produce by P, is consumed exactly once by P. (Notes: you may use additional variables, if needed. The space provided is not necessarily indicative of where code should be added.) monitor SingleBuffer // shared variables Items; entry void SetItem (Item il) s = il; } // end SetItem entry Item GetItem() Item i 2 = s; return i2; } // end GetItem } // end SingleBuffer Problem 4 - Process Synchronization (a) (10 points) Consider two processes that share a single variables of type Item such that process Po produces an item that is then consumed by process P. (Process' code given side-by-side to conserve space.) // shared variables Item s; // Process PO: // Process P1: // local variable Item il; // local variable Item i2; while (true) while (true) il = CreateItem(); i2 = s; UseItem (12); Show how semaphores can be used to provide the necessary synchronization so that every item produce by Po is consumed exactly once by P, by adding the use of semaphores to the code above. You should assume that Item assignment is an atomic operation. (Note: the space provided is not necessarily indicative of where code should be added.) (b) (10 points) Consider the same problem as in part (a) where Item s is enclosed in a monitor with entry procedures Settem and GetItem that allow processes to set and get s, respectively. Add code below to use condition variables so that the monitor provides the necessary synchronization to ensure every item produce by P, is consumed exactly once by P. (Notes: you may use additional variables, if needed. The space provided is not necessarily indicative of where code should be added.) monitor SingleBuffer // shared variables Items; entry void SetItem (Item il) s = il; } // end SetItem entry Item GetItem() Item i 2 = s; return i2; } // end GetItem } // end SingleBuffer

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

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

More Books

Students also viewed these Databases questions

Question

=+11-3 Describe the limbic system's structures and functions.

Answered: 1 week ago

Question

Describe the patterns of business communication.

Answered: 1 week ago

Question

3. Provide two explanations for the effects of mass media

Answered: 1 week ago