Lab 6 Solutions

Ice Cream Parlor was a lecture example created by Jerry Cain.

Before the end of lab, be sure to fill out the lab checkoff sheet here!

Before starting, get the starter code by cloning the lab6 folder:

$ git clone /usr/class/cs110/repos/lab6/shared lab6
$ cd lab6
$ make

Problem 1: Ice Cream Parlor

In this lab problem, we will implement a simulation of customers ordering ice cream in an ice cream parlor. The example is a bit contrived, but it allows us to work through a complex synchronization setup without actually having a very complicated program. You’ll see some applications of mutexes, semaphores, and condition variables that will be extremely helpful in Assignment 5.

The goal of this lab is to help you practice:

Simulation overview

This ice cream parlor comes from a somewhat odd universe:

Here are slides that walk through the various parts of the simulation: [keynote], [pdf]

Implementing the simulation

You can find the ice-cream-parlor.cc starter code in the lab6 directory (instructions for cloning are above). Alternatively, you can work through this cplayground.

Our final implementation is available here.

Customer/Clerk interactions

Clerk/Manager interactions

There are several things (mutexes, semaphores, etc) that we need to add here, related to synchronization in the manager’s office. To help organize these variables, our solution declares a ManagerOffice struct, although your solution does not need to do so. (You could just declare all these variables as direct members of IceCreamParlor.)

struct ManagerOffice {
    // manager-specific things here...
}

class IceCreamParlor {
  private:
    ManagerOffice managerOffice;
    // more stuff follows...
}

Customer/Cashier interactions

Similar to the manager’s office, our solution declares a struct containing variables that are specific to the checkout line. You do not have to do this.

struct CashierLine {
    // Cashier-specific fields here
};

class IceCreamParlor {
  private:
    ManagerOffice managerOffice;
    CashierLine cashierLine;
    // ... more stuff...
};

Electrician/Customer interactions