Question: C (not c++) programming help! Study problem Implement a simulation of a post office using semaphores. Prompt user for P, S, and M, where P
C (not c++) programming help! Study problem
Implement a simulation of a post office using semaphores. Prompt user for P, S, and M, where P is the number of people participating in the simulation, S is the number of messages a persons mailbox can hold, and M is the total number of messages to be sent before the simulation ends. You must use semaphores to control mailbox access when attempting to send a message to another person.
Procedure
After prompting the user for P, S, and M, fork several threads equal to the number of people involved in the simulation. Each person then proceeds according to the following algorithm:
- Enter the post office.
- Read a message in that persons mailbox.
- Call V () on a semaphore corresponding to that persons mailbox.
- Yield.
- IF there are more messages to read, GOTO 2.
- ELSE compose a message addressed to a random person other than themselves.
- Call P () on a semaphore corresponding to the recipients mailbox.
- Place the message in their mailbox.
- Leave the post office.
- Wait for 3-6 cycles.
- GOTO 1.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
