Skip to content

Category Archives: dino

Dining Philosopher Solutions

(Silberschatz et al, 6/e, Sec. 7.7)
Each philosopher must observe the protocol to eat:

dp.pickup(i);
// eat
dp.putdown(i);

But it impossible to enforce the protocol. (Limitation of monitors)
The book solution (Fig. 7.22) guarantees deadlock-free, since only one process is allowed active in the monitor, and a philosopher picks up chopsticks only when both are available.
The solution, however, is not starvation-free.
Let’s […]

Implementation of Monitors with Semaphores

(Silberschatz et al, 6/e, p. 220)
There are three design option for signaling process P and waiting process Q.

(Hoare)
P: waits until Q either a) leaves monitor (line 4), or b) waits for another condition (line 3).
(easier to prove)
(Brinch-Hansen)
Q: waits until P either a) leaves monitor (line 4), or b) waits for another condition (line 3).
(more reasonable, […]

Critical Region Implementation Using Semaphores

(Silberschatz et al., 6/e, p. 214)

region v when B do S; // S: critical section

Each such conditional critical region (or critical region) statement is mapped to the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
wait(mutex);
while (!B) {
first_count++;
if (second_count > 0) signal(second_delay);
else signal(mutex);
wait(first_delay);
first_count–;
second_count++;
if (first_count > 0) signal(first_delay);
else signal(second_delay);
wait(second_delay);
second_count–;
}
S; // critical section accessing V
if (first_count > 0) signal(first_delay);
else if (second_count > 0) signal(second_delay);
else signal(mutex);

first_delay: queues processes that fail evaluation of B
second_delay: […]