
CMSC 412
Spring 2007
Implementing Synchronization
Review
• What is synchronization?
– Why do we need it?
• What is deadlock?
– How related to synchronization?
• Reading: chapter 6.
Race Condition
•Race condition: The situation where several
processes access and manipulate shared data
concurrently. The final value of the shared
data depends upon which process finishes
last.
– Alternatively: when two accesses from different
threads to the same data are not causally
ordered, and at least one access is a write
• To prevent race conditions, concurrent
processes must be synchronized.
The Critical-Section Problem
•n processes all competing to use some
shared data
• Each process has a code segment, called
critical section, in which the shared
data is accessed.
• Problem – ensure that when one process
is executing in its critical section, no
other process is allowed to execute in
its (related) critical section.
Implementing Critical-Section
1.Mutual Exclusion. If process Pi is executing in its
critical section, then no other processes can be
executing in their critical sections.
2. Progress. If no process is executing in its critical
section and there exist some processes that wish to
enter their critical section, then the selection of
the processes that will enter the critical section
next cannot be postponed indefinitely.
3. Bounded Waiting. A bound must exist on the
number of times that other processes are allowed
to enter their critical sections after a process has
made a request to enter its critical section and
before that request is granted.
Assume that each process executes at a nonzero speed
No assumption of relative speed of the n processes.
Assumptions
• Some instructions are atomic, meaning
their effects are indivisible
– load, store, test instructions cannot be
interrupted
• Hardware configuration can vary
– Single or multiple processors