Question
Theater Simulation A theater is simulated by using threads to model customer and employee behavior. The objective is to use threads for each person and
Theater Simulation
A theater is simulated by using threads to model customer and employee behavior. The objective is to use threads for each person and to use semaphores to coordinate their activities. The threads to be used are as follows:
Customer:
- 50 customers are in line at the box office when the simulation starts (1 thread per customer).
- Movie titles and seats available are read from an input file.
- Each customer randomly chooses a movie and requests to buy a ticket from the box office.
- If the movie the customer wants to see is sold out, the customer leaves.
- The customer must see the ticket taker before entering the theaters main lobby.
- Each customer randomly chooses whether to visit the concession stand (50% chance to visit it).
- Each customer randomly visiting the concession stand randomly chooses popcorn, soda, or both.
Box Office Agents:
- Two created initially, one thread each.
- Serves next customer in line.
- Maintains count of tickets sold for each moviedoes not sell ticket if movie is sold out.
- If movie is sold out, this is communicated to the customer.
Ticket Taker:
- Created initially, one thread.
- Serves next customer in line.
- Takes and tears ticket.
Concession Stand Worker:
- Created initially, one thread.
- Serves next customer in line.
- Gets order from customer.
- Fills order.
Main
- Creates all threads and joins all customer threads.
- When last customer has exited, ends the simulation.
Other rules:
- Some actions take time (see table). The thread should sleep 1/60 of the time shown.
- Each activity of each thread should be printed with identification (e.g., customer 1).
- A thread may not use sleeping as a means of coordinating with other threads.
- Busy waiting (polling) is not allowed.
- Mutual exclusion should be kept to a minimum to allow the most concurrency.
- The semaphore value may not obtained and used as a basis for program logic.
- Each thread should print when it is created, and each customer should print when it is joined.
- All activities of a thread should only be output by that thread.
Sample output:
Output should match the wording of the sample output.
Box office agent 0 created
Box office agent 1 created
Ticket taker created
Concession stand worker created
Theater is open
Customer 1 created, buying ticket to Toy Story
Customer 2 created, buying ticket to Beauty and the Beast
Box office agent 0 serving customer 1
Customer 0 created, buying ticket to Wall-E
Box office agent 1 serving customer 2
Box office agent 1 sold ticket for Beauty and the Beast to customer 2
Box office agent 0 sold ticket for Toy Story to customer 1
Customer 1 in line to see ticket taker
Customer 2 in line to see ticket taker
Box office agent 1 serving customer 0
Ticket taken from customer 1
Customer 1 enters theater to see Toy Story
Ticket taken from customer 2
Customer 2 enters theater to see Beauty and the Beast
Box office agent 1 sold ticket for Wall-E to customer 0
Customer 0 in line to see ticket taker
Ticket taken from customer 0
Customer 0 in line to buy Popcorn
Order for Popcorn taken from customer 0
Popcorn given to customer 0
Customer 0 receives Popcorn
Customer 0 enters theater to see Wall-E
Joined customer 0
Joined customer 1
Joined customer 2
Task Table
Actor | Step | Time (seconds)
|
Ticket Taker
| Tear Ticket | 15
|
Concession Stand Worker | Fill Order | 180
|
Box Office Agent | Sell Ticket | 90
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started