libretto.examples.supermarket
Type members
Classlikes
Our supermarket specializes in the most wanted items in a pandemic, namely toilet paper and beer.
Our supermarket specializes in the most wanted items in a pandemic, namely toilet paper and beer.
In a pandemic, supermarkets are required to limit the number of customers in the store. A way to achieve it is to provide a limited number of shopping baskets and require that each customer entering the store has a shopping basket. When there are no more baskets, an incoming customer has to wait for a previous customer to leave (and return their basket).
In a pandemic, supermarkets are required to limit the number of customers in the store. A way to achieve it is to provide a limited number of shopping baskets and require that each customer entering the store has a shopping basket. When there are no more baskets, an incoming customer has to wait for a previous customer to leave (and return their basket).
This example demonstrates:
- concurrency
- customers come and shop concurrently
- sequencing
- a customer can shop only after obtaining a basket
- a customer can use an item only after paying for it
- ...
- mutual exclusion
- limited number of concurrently shopping customers
- without side-effects on shared synchronization objects (such as semaphores)
- limited number of concurrently shopping customers
- linear & session types
- obligation to return a basket enforced before execution
- the type
Shopping
is a protocol between the store and the customer