In: Computer Science
In the commentary on Figure 5.9 and Table 5.4, it was stated that “it would not do simply to move the conditional statement inside the critical section (controlled by s) of the consumer because this could lead to deadlock.” Demonstrate this with a table similar to Table 5.4.
|
|
Producer |
Consumer |
s |
n |
delay |
|
1
|
|
|
1
|
0
|
0
|
|
2
|
semWaitB(s)
|
|
0
|
0
|
0
|
|
3
|
n++
|
|
0
|
1
|
0
|
|
4
|
if (n==1)
|
|
0
|
1
|
1
|
|
|
(semSignalB(delay))
|
|
|
|
|
|
5
|
semSignalB(s)
|
|
1
|
1
|
1
|
|
6
|
|
semWaitB(delay)
|
1
|
1
|
0
|
|
7
|
|
semWaitB(s)
|
0
|
1
|
0
|
|
8
|
|
n--
|
0
|
0
|
0
|
|
9
|
|
if (n==0)
|
|
|
|
|
|
|
(semWaitB(delay))
|
|
|
|
|
10
|
semWaitB(s)
|
|
|
|
|


















Both producer and consumer are blocked.
Both producer and consumer are blocked.