Professional Documents
Culture Documents
“On my honor, as student of Sir Syed CASE Institute Islamabad, I have neither given nor
received unauthorized assistance on this academic work.”
Submitted to:
Sir Waqas
DATE
For the following cases explain clearly how mutual exclusion and
bounded waiting property can be satisfied for 4 processes(P0, P1,
P2, P3).
1) if P0 want to access critical section again and again and no
other process access critical section.
Solution:
In this case, mutual exclusion and bounded waiting properties will be satisfied for
all processes. Since P0 is the only process accessing the critical section, it will not
have to wait for any other process to release the lock. Additionally, since no other
process is accessing the critical section, there is no possibility of any process
waiting indefinitely, thus the bounded waiting property is also satisfied.
do {
waiting[i] = TRUE;
key = TRUE;
while (waiting[i] && key)
key = TestAndSet(&lock);
waiting[i] = FALSE;
// critical section
j = (i + 1) % n;
while ((j != i) && !waiting[j])
j = (j + 1) % n;
if (j == i)
lock = FALSE;
else
waiting[j] = FALSE;
// remainder section
} while (TRUE);