NOTE
Synchronization
[toc] 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 the same time. 1.2.1. Critical Sectio
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 the same 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
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub