CS110: Principles of Computer Systems

Autumn 2021
Jerry Cain

PDF

Threading and Ice Cream Parlors

  • Our ultimate multithreaded program simulates the daily activity in an ice cream parlor. The players are the clerks who make ice cream cones, the single manager who supervises, the customers who buy ice cream cones, and the single cashier who accepts payment from customers. A different thread is launched for each.
    • Each customer orders a few ice cream cones, waits for them to be made, gets in line to pay, and then leaves. customers are in a big hurry and don’t want to wait for one clerk to make several cones, so each customer dispatches one clerk thread for each ice cream cone he or she orders. Once the customer has all ordered ice cream cones, he/she gets in line at the cashier and waits his/her turn. After paying, each customer leaves.
    • Each clerk thread makes exactly one ice cream cone. The clerk makes a cone and then has the manager take a look to make sure it's all good. If the cone doesn't pass muster, it is thrown away and the clerk makes another. Once an ice cream cone is approved, the clerk hands the gem of an ice cream cone to the customer and is then done.
    • The single manager sits idle until a clerk needs his or her freshly scooped ice cream cone inspected. When the manager hears of a request for an inspection, he/she determines if it passes and lets the clerk know how the cone fared. The manager is done when all cones have been approved.
    • The customer checkout line must be maintained in FIFO order. After getting their cones, a customer "takes a number" to mark their place in the cashier queue. The cashier always processes customers from the queue in order
    • The cashier naps while there are no customers in line. When a customer is ready to pay, the cashier handles the bill. Once the bill is paid, the customer can leave. The cashier should handle the customers according to number. Once all customers have paid, the cashier is finished and leaves.
  • ​We'll walk through the core of this problem and its solution together during lecture.
Made with Slides.com