Process Synchronization


  1. Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin, "Operating System Concepts, Ninth Edition ", Chapter 5

Warning: This chapter requires some heavy thought. As you read each of the algorithms below, you need to satisfy yourself that they do indeed work under all conditions. Think about it, and don't just accept them at face value.

5.1 Background

Consumer code from chapter 3:

5.2 The Critical-Section Problem

Figure 5.1 - General structure of a typical process Pi

5.3 Peterson's Solution

Figure 5.2 - The structure of process Pi in Peterson's solution.

5.4 Synchronization Hardware

Figures 5.3 and 5.4 illustrate "test_and_set( )" function

Figure 5.7 Bounded-waiting mutual exclusion with TestAndSet( ).

5.5 Mutex Locks

Figure 5.8 - Solution to the critical-section problem using mutex locks

5.6 Semaphores

5.6.1 Semaphore Usage

5.6.2 Semaphore Implementation

5.6.3 Deadlocks and Starvation

5.6.4 Priority Inversion

5.7 Classic Problems of Synchronization

The following classic problems are used to test virtually every new proposed synchronization algorithm.

5.7.1 The Bounded-Buffer Problem

Figures 5.9 and 5.10 use variables next_produced and next_consumed

5.7.2 The Readers-Writers Problem

5.7.3 The Dining-Philosophers Problem

Figure 5.13 - The situation of the dining philosophers

Figure 5.14 - The structure of philosopher i.

5.8 Monitors

5.8.1 Monitor Usage

Figure 5.15 - Syntax of a monitor.

Figure 5.16 - Schematic view of a monitor

Figure 5.17 - Monitor with condition variables

Signal and wait - When process P issues the signal to wake up process Q, P then waits, either for Q to leave the monitor or on some other condition.

Signal and continue - When P issues the signal, Q waits, either for P to exit the monitor or for some other condition.

There are arguments for and against either choice. Concurrent Pascal offers a third alternative - The signal call causes the signaling process to immediately exit the monitor, so that the waiting process can then wake up and proceed.

5.8.2 Dining-Philosophers Solution Using Monitors

5.8.3 Implementing a Monitor Using Semaphores

5.8.4 Resuming Processes Within a Monitor

Figure 5.19 - A monitor to allocate a single resource.

5.9 Synchronization Examples ( Optional )

This section looks at how synchronization is handled in a number of different systems.

5.9.1 Synchronization in Windows

Figure 5.20 - Mutex dispatcher object

5.9.2 Synchronization in Linux

5.9.3 Synchronization in Solaris

Adaptive Mutexes

Reader-Writer Locks


5.9 4 Pthreads Synchronization( was 6.8.4 )

5.10 Alternate Approaches ( Optional )

5.10.1 Transactional Memory

5.10.2 OpenMP

5.10.3 Functional Programming Languages

5.11 Summary

Old 6.9 Atomic Transactions ( Optional, Not in Ninth Edition )

6.9.1 System Model

6.9.2 Log-Based Recovery

6.9.3 Checkpoints

6.9.4 Concurrent Atomic Transactions Serializability Locking Protocol Timestamp-Based Protocols