Synchronizing Execution

If sequential execution means being the only person at the party, immutability is having a plastic cake, and isolation is giving everyone their own cake, then synchronization is having many guests and one cake and asking your great aunt Matilda to make everyone act politely. Matilda makes sure that everyone gets a piece of the cake by having the guests take turns and play nice.

Synchronization means making Tasks take turns, avoiding races by serializing access to shared data, usually only allowing one Task access to the shared data at any given time (although there are other options that we will cover in Chapter 4).

The two key elements to understanding synchronization are the critical region and the synchronization primitive. In party terms, critical regions are the cakes, or the things that we want to control access to in order to avoid problems. Synchronization primitives play the role of the great aunt, or the way in which we enforce order and politeness.

0 0

Post a comment