Unit 2 Lecture 31 - Classic Problems of Synchronization
Unit 2 Lecture 31 - Classic Problems of Synchronization
UE22CS242B
Classic problems of Synchronization
Chandravva Hebbi
Department of Computer Science
OPERATING SYSTEMS
Slides Credits for all the PPTs of this course
Suresh Jamadagni
Department of Computer Science
OPERATING SYSTEMS
Bounded-Buffer Problem
● solution
● Several variations of how readers and writers are considered – all
involve some form of priorities
● Shared Data
● Data set
● Semaphore rw_mutex initialized to 1(semaphore)
● Semaphore mutex initialized to 1 (mutex)
● Integer read_count initialized to 0
OPERATING SYSTEMS
Readers-Writers Problem (Cont.)
do {
wait(rw_mutex);
...
/* writing is performed */
...
signal(rw_mutex);
} while (true);
OPERATING SYSTEMS
Readers-Writers Problem (Cont.)
● Deadlock handling
● Allow at most 4 philosophers to be sitting simultaneously at the table.
● Allow a philosopher to pick up the chopsticks only if both are available
(picking must be done in a critical section).
● Use an asymmetric solution -- an odd-numbered philosopher picks up
first the left chopstick and then the right chopstick. Even-numbered
philosopher picks up first the right chopstick and then the left chopstick.
THANK YOU
Suresh Jamadagni
Department of Computer Science Engineering
[email protected]