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

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

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

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!