Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Post Office Simulation -A Post Office is simulated by using threads to model customer and employee behavior. -This project is similar to the barbershop example

Post Office Simulation

-A Post Office is simulated by using threads to model customer and employee behavior.

-This project is similar to the barbershop example in the textbook. The following rules apply:

Customer:

1)50 customers visit the Post Office (1 thread per customer up to 50), all created initially.

2)Only 10 customers can be inside the Post Office at a time.

3)Each customer upon creation is randomly assigned one of the following tasks:

a)buy stamps

b)mail a letter

c)mail a package

4)Times for each task are defined in the task table.

Postal Worker:

1)3 created initially, one thread each.

2)Serves next customer in line.

3)Service time varies depending on customer task.

Scales:

1)Used by the postal worker when mailing a package.

2)There is only one, which can only be used one at a time.

3)The scales are not a thread. They are just a resource the postal worker threads use.

Other rules:

1)A thread should sleep 1 second in the program for each 60 seconds listed in the table.

2)All mutual exclusion and coordination must be achieved with semaphores.

3)A thread may not use sleeping as a means of coordination.

4)Busy waiting (polling) is not allowed.

5)Mutual exclusion should be kept to a minimum to allow the most concurrency.

6)Each thread should print when it is created and when it is joined.

7)Each thread should only print its own activities. The customer threads prints customer actions and the postal worker threads prints postal worker actions.

8)Your output must include the same information and the same set of steps as the sample output.

Output:

1)Each step of each task of each thread should be printed to the screen with identifying numbers so it is clear which threads are involved.

2)Thread output sample. The wording in your output should exactly match the sample.

Simulating Post Office with 50 customers and 3 postal workers

Postal worker 0 created

Postal worker 2 created

Postal worker 1 created

Customer 0 created

Customer 0 enters post office

Customer 9 created

Customer 9 enters post office

Customer 10 created

Postal worker 0 serving customer 0

Customer 11 created

Postal worker 2 serving customer 1

Postal worker 1 serving customer 2

Customer 0 asks postal worker 0 to buy stamps

Customer 2 asks postal worker 1 to mail a package

Customer 1 asks postal worker 2 to mail a package

Scales in use by postal worker 1

Postal worker 0 finished serving customer 0

Customer 0 finished buying stamps

Postal worker 0 serving customer 3

Customer 3 asks postal worker 0 to mail a letter

Customer 0 leaves post office

Customer 10 enters post office

Joined customer 0

Scales released by postal worker 1

Postal worker 1 finished serving customer 2

Customer 5 asks postal worker 1 to mail a package

Scales in use by postal worker 2

Customer 2 finished mailing a package

Postal worker 1 serving customer 5

Customer 2 leaves post office

Postal worker 0 finished serving customer 3

Customer 3 finished mailing a letter

Postal worker 0 serving customer 4

Customer 4 asks postal worker 0 to mail a letter

Customer 3 leaves post office

Scales released by postal worker 2

Postal worker 2 finished serving customer 1

Scales in use by postal worker 1

Customer 1 finished mailing a package

Customer 1 leaves post office

Joined customer 1

Joined customer 2

Joined customer 3

TABLE TASK:

buy stamp: 60 sec

mail a letter : 90 sec

mail a package: 120 sec (sclases are used entire time)

***DESIGN NEED TO BE SIMILAR TO THE FOLLOWING BARBER SHOP PSEUDOCODE USING WAIT AND SIGNAL CALL

image text in transcribed

program barbershop1 semaphore sofa*4; semaphore barber chair semaphore coord -3; semaphore cust ready 0, finished-0, eave b chair 0, paymen 0, receipt 0 void barber void cashier 0 void customer o while (true) while (true) wait(max capacity); enter shop0, wait payment); wait (cust ready); wait(sofa); wait (coord); sit on sofa0; wait(coord); accept payo; cut hairo; wait(barber chair); signal (coord); get up from sofa0; signal (coord); signal (receipt); signal(sofa), signal(finished); sit in barber chairo; wait leave b chair); signal (cust ready); signal barber chair); wait(finished); leave barber chairo; signal(leave b chair); pay0; signal (payment); wait(receipt). exit shop signal(max capacity)

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

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago