NOTE

Synchronization

Synchronization coordinates execution order, while mutual exclusion restricts concurrent entry into a critical section. These notes compare those coordination needs.

Operating Systems / LinuxCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Synchronization and Mutual Exclusion

1.1. Synchronization

Multiple processes execute in a certain order.

1.2. Mutual Exclusion

Among multiple processes, only one process can enter the critical section at a time.

1.2.1. Critical Section

Code that accesses the same resource is called a critical section.

2. Synchronization Methods

2.1. Semaphore

An integer variable on which down and up operations can be performed.

  • down: if the semaphore is greater than 0, perform a -1 operation; if the semaphore equals 0, the process sleeps and waits for the semaphore to become greater than 0.
  • up: perform a +1 operation on the semaphore and wake a sleeping process so that it can complete the down operation.

2.1.1. Mutex

If the semaphore can only take the value 0 or 1, it becomes a mutex. 0 means the critical section is locked, and 1 means the critical section is unlocked.

2.2. Monitor

Semaphores require handling many details, so monitors were introduced. A monitor introduces Condition operations: wait() and signal.

3. Classic Synchronization Problems

3.1. Producer/Consumer Problem

  • Semaphore
    • Mutex
  • Monitor

3.2. Readers/Writers Problem

3.3. Dining Philosophers Problem

4. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub