5. (26pts) Consider the following scenario: Process 0 is responsible for generating a random integer for the other processes to use. Each random number can be used by only one process. The random number can be passed to the other processes through an integer. The integer can be considered to be in one of two states. The integer is “empty” if Process 0 has not yet generated a random number or if the random number had been used by a processes. The integer is considered “full” if Process 0 stored a random number in it, and it has not yet been used by a process. Processes 1 - 10 will each use one random number.
Write psudocode for this scenario that uses:
(a) A monitor (b) Messages
Procedure CheckStatus {
Initialize integer x; //used for passing random value from process 0 to other process
Initialize Process P0; //used to generate random numbers and to pass these values to other processes
Integer check;
P0_random = rand();
for each value of Pi:
Pi = P0_random;
if P0 did not generate any random value (or) Pi has already accepted the given integer:
check = 'empty';
else:
check = 'full';
end for
}
Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! ===========================================================================
Get Answers For Free
Most questions answered within 1 hours.