Page 151 - DCAP103_Principle of operating system
P. 151
Principles of Operating Systems
Notes 4.9 Review Questions
1. State a simple rule for avoiding deadlocks in this system.
2. Consider the deadlock situation that could occur in the dining-philosophers Problem when
the philosophers obtain the chopsticks one at a time. Discuss How the four necessary
conditions for deadlock indeed hold in this Setting. Discuss how deadlocks could be
avoided by eliminating any one of the four conditions.
3. What is the meaning of the term busy waiting? What other kinds of waiting are there in
an operating system? Can busy waiting be avoided altogether? Explain your answer.
4. The first known correct software solution to the critical-section problem for n processes
with a lower bound on waiting of n - 1 turns was presented by Eisenberg and McGuire.
The processes share the following variables enum pstate {idle, want-in, in-cs);
pstate flagCnl ; i n t turn;
do {
flag[i] = true;
while (flag[j]) {
if (turn == j) {
flag[i] = false;
while (turn == j);
flag[i] = true;
}
}
critical section
turn = j;
flag[i] = false;
remainder section
while (1);
The structure of process Pi in Dekker’s algorithm.
All the elements of flag are initially idle; the initial value of turn is immaterial (between 0
and n-1). The structure of process Pi is shown below.
do {
while(1) {
flag[i] = want-in;
j = turn;
while (j ! = i) {
if (flag[j] != idle)
j = turn;
else
j = (j+1) % n;
}
144 LOVELY PROFESSIONAL UNIVERSITY