


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of process synchronization techniques, focusing on semaphores, monitors, and condition variables. Topics include weak and strong semaphores, the bounded-buffer problem, readers-writers problem, dining philosophers problem, and monitor initialization code. The document also covers problems with semaphores and the use of condition variables in solving the dining philosophers problem.
Typology: Slides
1 / 42
This page cannot be seen from the preview
Don't miss anything!



































Order of arrival retainment:
The thread that will access the critical region next is selected randomly
Starvation is possible
The thread that will access the critical region next is selected based on its arrival time, e.g. FIFO
Starvation is not possible
Starvation
Classical Problems of Synchronization
do {
// produce an item in nextp
wait (empty); wait (mutex);
// add the item to the buffer
signal (mutex); signal (full); } while (TRUE);
do { wait (full); wait (mutex);
// remove an item from buffer to nextc
signal (mutex); signal (empty);
// consume the item in nextc
} while (TRUE);
do { wait (mutex) ; readcount ++ ; if (readcount == 1) wait (wrt) ; signal (mutex)
// reading is performed
wait (mutex) ; readcount - - ; if (readcount == 0) signal (wrt) ; signal (mutex) ; } while (TRUE);
Solution to Dining Philosophers
sequence:
DiningPhilosophters.pickup (i); EAT DiningPhilosophers.putdown (i);
monitor DP
{
enum { THINKING; HUNGRY, EATING) state [5] ; condition self [5];
initialization_code() { for (int i = 0; i < 5; i++) state[i] = THINKING; }
{
boolean busy; condition x;
void acquire(int time) { if (busy) x.wait(time); busy = TRUE; }
void release() { busy = FALSE; x.signal(); }
initialization code() { busy = FALSE; }
}