Let us first understand wait and signal operation.
wait(): process which performs wait operation
on condition variable c will get suspended and will be placed in
block queue of c.
signal(): Wherever a process performs a signal
operation on condition variable c, one process from blocked queue
of c will be executed. If block queue is empty, this will be
ignored.
Let us represent block queue by q.
(a) Initially, x = 10, y = 2, q is empty.
m.A() : line 1 : x++; x = 11
line 2 : c.signal : q empty : ignore signal
line 3 : y = x- 2; y = 11 - 2 = 9
Now, x = 11, y = 9, q empty
m.B() : line 4 : if (x > 10) : true as x =
11
line 5 : x--; x = 10
Now, x = 10, y = 9, q empty
m.B() : line 4 : if (x > 10) : false as x =
10
line 6 : c.signal : this process will be placed in q
Now, x = 10, y = 9, q = (m.B())
m.B() : line 4 : if (x > 10) : false as x =
10
line 6 : c.signal : this process will be placed in q
Now, x = 10, y = 9, q = (m.B(), m.B())
m.B() : line 4 : if (x > 10) : false as x =
10
line 6 : c.signal : this process will be placed in q
Now, x = 10, y = 9, q = (m.B(), m.B(), m.B())
m.A() : line 1 : x++; x = 11
line 2 : c.signal : run first m.B() from q : line 7 : x-- : x =
10
Now, x = 10, y = 9, q = (m.B(), m.B())
m.A() : line 1 : x++; x = 11
line 2 : c.signal : run first m.B() from q : line 7 : x-- : x =
10
Final values will be x = 10, y = 9, q = (m.B())
Exercise 4.4.1: Tracing a monitor execution. About While a process is executing inside the function A...