Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. 50 customers are in line at the box office when the simulation starts (1 thread per customer).
  2. Movie titles and seats available are read from an input file.
  3. Each customer randomly chooses a movie and requests to buy a ticket from the box office.
  4. If the movie the customer wants to see is sold out, the customer leaves.
  5. The customer must see the ticket taker before entering the theaters main lobby.
  6. Each customer randomly chooses whether to visit the concession stand (50% chance to visit it).
  7. Each customer randomly visiting the concession stand randomly chooses popcorn, soda, or both.

Box Office Agents:

  1. Two created initially, one thread each.
  2. Serves next customer in line.
  3. Maintains count of tickets sold for each moviedoes not sell ticket if movie is sold out.
  4. If movie is sold out, this is communicated to the customer.

Ticket Taker:

  1. Created initially, one thread.
  2. Serves next customer in line.
  3. Takes and tears ticket.

Concession Stand Worker:

  1. Created initially, one thread.
  2. Serves next customer in line.
  3. Gets order from customer.
  4. Fills order.

Main

  1. Creates all threads and joins all customer threads.
  2. When last customer has exited, ends the simulation.

Other rules:

  1. Some actions take time (see table). The thread should sleep 1/60 of the time shown.
  2. Each activity of each thread should be printed with identification (e.g., customer 1).
  3. A thread may not use sleeping as a means of coordinating with other threads.
  4. Busy waiting (polling) is not allowed.
  5. Mutual exclusion should be kept to a minimum to allow the most concurrency.
  6. The semaphore value may not obtained and used as a basis for program logic.
  7. Each thread should print when it is created, and each customer should print when it is joined.
  8. 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

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions