Next: Thread Basics
Up: Shared Memory Programming
Previous: Communication
Contents
Synchronization
Figure 4.10:
Locks and barriers.
|
- Synchronization is needed to protect shared variables by ensuring that they are accessed by only one process at a given time (mutual exclusion).
- They can also be used to coordinate the execution of parallel processes and synchronize at certain points in execution.
- There are two main synchronization constructs in shared
memory systems:
- locks
- barriers.
- Figure 4.10a shows three parallel processes using locks to ensure mutual exclusion. Process P2 has to wait until P1 unlocks the critical section; similarly P3 has to wait until P2 issues the unlock
statement.
- In Figure 4.10b, P3 and P1 reach their barrier statement before P2, and they have to wait until P2 reaches its barrier. When all three reach the barrier statement, they all can proceed.
Next: Thread Basics
Up: Shared Memory Programming
Previous: Communication
Contents
Cem Ozdogan
2006-12-27