3,737 views

Consider the following program segment for concurrent processing using semaphore operators $P$ and $V$ for synchronization. Draw the precedence graph for the statements $S_1$ to $S_9$.

var
a,b,c,d,e,f,g,h,i,j,k : semaphore;
begin
cobegin
begin S1; V(a); V(b) end;
begin P(a); S2; V(c); V(d) end;
begin P(c); S4; V(e) end;
begin P(d); S5; V(f) end;
begin P(e); P(f); S7; V(k) end
begin P(b); S3; V(g); V(h) end;
begin P(g); S6; V(i) end;
begin P(h); P(i); S8; V(j) end;
begin P(j); P(k); S9 end;
coend
end;

1 comment

It is not given that all Semaphores are Binary Semaphores with initial value = 0. How can we draw such graph, if it is not mentioned?

Precedence graph will be formed as$:$

Thats correct. All statements between cobegin and coend starts executing simultaneously, P(i) does wait operation on semaphore i, and V(i) does signal operation on i.
Nice Thank you.

It is not given that all Semaphores are Binary Semaphores with initial value = 0. How can we draw such graph, if it is not mentioned?

U are right it is not mentioned that semaphore is initialized to zero.
Please share some resource on how to draw these

why there is direct edge from S3->S8 ?

Before S8 P(h), P(i) is present.

And V(h) is provided by S3.

And V(i) is provided by S6.

So S3 and S6 both has direct edge to S8.