Shared Mutable Design

Our first approach to total work years is a familiar approach: write 0 on the board and ask everyone to walk up to add their work years to that total.

Fred, who’s closest to the board, jumps up to add his years to the total, and before we know it, a number of people have lined up, creating contention around the board. As soon as Fred is done, Jane gets her turn. We’ll have to keep an eye to ensure pranksters don’t change the entry to something impossible like infinity.

Shared mutability is at work here, along with the challenges it brings. We have to police more than one person trying to change the number at a given time. Furthermore, people have to patiently wait for their turn to write on the board as each person takes ...

Get Programming Concurrency on the JVM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.