OS PPT 3-4
OS PPT 3-4
UNIT III
.
Synchronization Tools
• The Critical-Section Problem
• Peterson’s Solution
• Synchronization Hardware
• Mutex Locks
• Semaphores
• Alternative Approaches
Synchronization
• Concurrent access to shared data may result in data
inconsistency
• Maintaining data consistency requires mechanisms to
ensure the orderly execution of cooperating processes
• The synchronization mechanism is usually provided
by both hardware and the operating system
• Illustration of the problem – The producer-Consumer
problem
• Basic assumption – load and store instructions are
atomic.
Producer-Consumer Problem in Cooperative process
do {
while (turn == j);
critical section
turn = j;
remainder section
} while (true);
■ Algorithm is correct. Only one process at a time in the critical section. But:
■ Results in “busy waiting”.
■ If Pi wants to enter then critical section and turn = j and Pj does not want to
enter the critical section ….
Solution to Critical-Section Problem
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 concerning relative speed of the n processes