
Suppose you're on a plane with a very narrow aisle and only one toilet. If you need the loo, you could just get up and stand in a physical queue. But that means you can't keep watching your movie. And, more importantly, you'll also block the aisle and the drinks trolley won't be able to get through. To avert this crisis in the skies, we propose the LamportPlus Loo-Q system!
Clear aisles, fair queues, no negotiations required
No one is thinking clearly on a long flight, and no one wants to get into complex negotiations for how queues should work, particularly when people are busting for the toilet. The solution we need is something that can do the following:
- No queue forms in the aisle – the drinks trolley can always get through;
- Fair is fair – requests for the toilet are granted in the order in which they are made;
- Everyone who has requested the loo will eventually get to go (well, at least up until the point the plane begins its descent for landing);
- Finally, perhaps the most vital thing is that there is no need to talk to anyone. And you get to stay in your seat watching your movie for as long as possible.
To solve this problem for us the passengers, and to do it as easily and cheaply as possible for the airlines, our Loo-Q program just needs to be added to the in-seat entertainment system. Then each seat will run its own queue and no central computer is necessary to coordinate things. Loo-Q is a distributed system: the entertainment system in each seat runs a separate process, communicating with the other processes (ie, seats) via messages. (You can read more about distributed systems in Distributed systems and ambiguous histories.)
For simplicity we need to make a couple of assumptions:
- For any two seats
and , the messages from to are received in the order they are sent, and every message sent will eventually be received. (You could make sure of this by introducing message numbers and acknowledgement protocols – but we're keeping it simple here by making this assumption). - Every seat can message every other seat.
The algorithm

The spacetime diagram for an example of the Loo-Q system in action! You can see the example in full here.
The Loo-Q algorithm is based on the example in Leslie
Lamport's paper Time,
clocks, and the ordering of events in a distributed system,
that is one of the most cited papers in computer science.
The Loo-Q system works by every seat maintaining its own local queue,
Rule 1: If you need the loo
you press your Loo-Q button. Your seat,
Rule 2: If your seat,
Rule 3: Your Loo-Q button, for seat
- There's a "
" request at the front of your local queue (so no other timestamped requests come before it); and - Your seat,
, has received a message from every other seat timestamped later than . (So either a receipt message – Rule 2, a request message – Rule 1, or a release message – Rule 4).
Rule 4: When you've finished with the loo and returned
to your seat, your seat increases its local clock
Rule 5: If your seat,
Rule 6: If your seat,
You can see a worked example, showing the Loo-Q system in action for three of the seats on a plane, here.
Clear aisles and relieved passengers
You might ask: Why go through all this palaver? It will be well worth it if it meets the specifications we set for our Loo-Q system:
- No queue forms in the aisle – the drinks trolley can always get through;
- No queue jumping – requests for the toilet are granted in the order in which they are made;
- Everyone who has requested the loo will eventually get to go (well, at least up until the point the plane begins its descent for landing);
- No need to talk to anyone – you get to stay in your seat watching your movie for as long as possible.
No queue forms in the aisle: You only get up for the loo if your Loo-Q button goes green. Rule 3 says this only happens if:
- The message "
" is first in your local queue, ; and - Your seat has received a message from every other seat with a timestamp later than
.
- A receipt of your loo request – indicating their queue is synchronised with yours, and you're good to go to the loo; or
- Their request for the loo, in which case:
- If their request is timestamped later than yours, then your position is unchanged and you are good to go to the loo; or
- If their request is timestamped earlier than yours then you get bumped from the front of your local queue and you'll have to wait until they've finished, at which point they'll send you a finished message timestamped later than your request.
So your button only goes green once everyone requesting the loo earlier than you has been to the loo (Rule 3) and has returned to their seat and sent their finished messages (Rules 4 and 5). No queue forms in the aisle.
The Loo-Q system is fair, requests for the toilet are granted in the order in which they are made: Again, the second part of Rule 3 guarantees this.
Everyone who has requested the loo will eventually get to go (up to the point the plane begins its descent for landing): Everyone who goes to the loo has to return to their seat (so the drinks trolley can get through), so their Loo-Q button will eventually turn off, their finished messages will be sent and their request will be removed from all the local queues. So, given enough time, each request will eventually reach the front of their queue and pass Rule 3.
No need to talk to anyone – you get to stay in your seat watching your movie for as long as possible: This final specification is satisfied thanks to the wonder of the distributed nature of this algorithm. Hooray for distributed algorithms and hooray for Leslie Lamport and his logical clocks!
You can see a worked example, showing the Loo-Q system in action for three of the seats on a plane, here.
About this article

This article is part of our Stuff happens: the physics of events project, run in collaboration with FQXi. Click here to see more articles and videos about the role of events, special relativity and logical clocks in distributed computing.
Rachel Thomas is Editor of Plus. She interviewed Leslie Lamport in September 2016 at the Heidelberg Laureate Forum.