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:

  1. Enter the post office.
  2. Read a message in that persons mailbox.
  3. Call V () on a semaphore corresponding to that persons mailbox.
  4. Yield.
  5. IF there are more messages to read, GOTO 2.
  6. ELSE compose a message addressed to a random person other than themselves.
  7. Call P () on a semaphore corresponding to the recipients mailbox.
  8. Place the message in their mailbox.
  9. Leave the post office.
  10. Wait for 3-6 cycles.
  11. GOTO 1.

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!