Upload
baraveli-kakuni
View
217
Download
0
Embed Size (px)
Citation preview
8/2/2019 The Sleepy Salon
1/4
The Sleepy Salon
The Problem
Three hairdressers work independently in a salon shop:
The salon has 3 salon chairs, each of which is assigned to one hairdresser.
Due to budget restrictions, there are only 2 combs and 2 scissors in the salons.
Each hairdresser follows the same work plan:
- The hairdresser sleeps when no customer is in waiting (and is not in the hairdressers ownchair).
- When the hairdresser is asleep, the hairdresser waits to be awakened by a new customer. (asign in the shop indicates which salon has asleep longest, so the customer will know which
hairdresser to awake up if multiple hairdressers are asleep.)
- Once awake, the hairdresser cuts the hair of a customer in the hairdressers chair.- The hairdresser requires a comb and a pair ofscissors to cut a customers hair. When the
haircut is done, the customer pays the hairdresser and then is free to leave.
- After receiving payment, the hairdresser calls the next waiting customer (if any). If such acustomer exists, that customer sits in the hairdressers chair and the hairdresser starts the
next haircut, if no customer is waiting, the hairdresser goes back to sleep.
Each customer follows the following sequence of events.
- When the customer first enters the salons, the customer leaves immediately if more than 20people are waiting (10 standing and 10 sitting). On the other hand, if the salon is not too full,
the customer enters and waits.
- If at least one hairdresser is sleeping, the customer looks at a sign, wakes up the hairdresserwho has been sleeping the longest, and sits in that hairdressers chair (after the hairdresser
has stood up).
- If all hairdressers are busy, the customer sits in a waiting-room chair, if one is available.Otherwise, the customer remains standing until a waiting-room chair becomes available.
8/2/2019 The Sleepy Salon
2/4
- Customers keep track of their order, so the person sitting the longest is always the nextcustomer to get a haircut.
- Similarly, standing customers remember their order, so the person standing the longesttakes the next available waiting-rom seat.
Deliverables:
For this exercise, you are to model the salon in FSP and write a Java program to simulate activity for
this salon:
Simulate each hairdresser and each customer as a separate process.
Altogether, 30 customers should try to enter.
Use a random number generator, so a new customer arrives every 1,2,3 or 4 seconds. (this might be
accomplished by an appropriate statement sleep (1+(rand()%4)).
Similarly, use a random number generator, so each haircut lasts between 3 and 6 seconds.
Each hairdresser should report when he/she starts each haircut and when he/she finishes each
haircut.
Each customer should report when he/she enters the salon. The customer also should report if
he/she decides to leave immediately.
Similarly, if the customer must stand or sit in the waiting room, the customer should report when
each activity begins.
Finally, the customer should report when the haircut begins and when the customer finally exits the
shop.
Sample output
In order to see what is happening dynamically you must have output from the customers and the
hairdressers reporting all their major events.
Add information about which process/thread is doing the output. This way you can see if aprocess/thread acts for another, which is strictly forbidden, but is a common error for Java solutions
(objects are not processes!). An example of such incorrect behaviour is
Thread-Hairdresser: 21.31: Hairdresser1: Customer 3 is done!
Main: 21:50: Hairdresser: Next customer please!
Thread-Customer-12: 21.50: Customer12 is waiting for a chair.
Thread-Hairdresser: 21.31: Hairdrsser2: Acquiring comb2!
8/2/2019 The Sleepy Salon
3/4
Where you can see that not only the hairdresser thread but also the main thread is acting for the
hairdresser.
Note that realistic stamps are not required, it is fine to use any function to generate them.
You must not
- Kill a thread or process. You may not use any of the following primitives in Java:- Thread.stop
- Thread.resume
- Thread.suspend
- Thread.interrupt
- setDaemon
You may not use the destroy or stop(0) primitives in except to take care of temporary resources
like simple timers.
If any of those primitives are found in your code, you will fail the assignment no matter the
functionality of it.
- Solve the last orders problem in a manner forbidden in the description above.- Resolve communication with an all-purpose one-channel solution.
8/2/2019 The Sleepy Salon
4/4
Tips
- Run your program without customers entering the salon. This should work if your solution iscorrect. The solutions should not be dependent on the events created by customers.
- Make very sure of whos actually doing the work. Make this easier for yourself by printingthe name of the process performing an action.
- The use of semaphores (other than for controlling simple resources and basic mutex forstatistics) is strongly discouraged.
- Use short delay times there is no need for a simulation run to take more than 20-30seconds.
- You do not need to implement a ticker.Implementation
You should implement your simulation in Java.
Caution!
It might be tempting to use the Thread.interrupt() method to wake sleeping processes. This is a bad
idea. Firstly, we have seen what a mess people can get into with this! Secondly, a behaviour which is
present in every execution of the program is not exceptional, and is usually considered bad
programming style to use an exception in such cases. In summary, dont use Thread.interrupt().
Documentation
The documentation should contain the following:
- Appropriate FSP statements.- Appropriate LTS diagrams (you should used traces where applicable).- Structure diagram where applicable.- Requirements as seen from the marking scheme.- UML class diagram of your implementation in Java (your source code must correspond
against your UML class diagram).
- Explanation on sections of codes which you spent most time (include code extracts) on andalso include discussion of section that did not work as expected.
- Other relevant discussions/diagrams.- Describe any modifications, assumptions and basic design decisions that have been made
about the behaviour of the various components of the simulation.