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...
QUESTION 1 Process P1 waits on the condition x in the monitor M. Process P2 calls x.signal() within a function defined in the same monitor M. What further scenario is possible? (Check all that apply.) Process P2 is suspended. Process P1 resumes the execution. Process P1 resumes the execution. Process P2 continues the execution. Process P2 continues the execution. Process P1 is nonetheless suspended until P2 leaves the monitor. The operation x.signal() fails. QUESTION 2 The following pseudocode fragment adds...