recategorized by
5,674 views
25 votes
25 votes

Write a concurrent program using $\text{parbegin-parend}$ and semaphores to represent the precedence constraints of the statements $S_1$ to $S_6$, as shown in figure below.

recategorized by

4 Answers

Best answer
30 votes
30 votes
parbegin

    begin   S1  parbegin    V(a)    V(b)    parend  end
    
    begin   P(a)    S2  parbegin    V(c)    V(e)    parend  end
    
    begin   P(b)    S3  V(d)    end
    
    begin   P(f)    P(c)    S4  end
    
    begin   P(g)    P(d)    P(e)    S5  end
    
    begin   S6  parbegin    V(f)    V(g)    parend  end
    
parend

Here, the statement between parbegin and parend can execute in any order. But the precedence graph shows the order in which the statements should be executed. This strict ordering is achieved using the semaphores.

Initially all the semaphores are $0.$

For $S_1$ there is no need of semaphore because it is the first one to execute.

Next $S_2$ can execute only when $S_1$ finishes. For this we have a semaphore $a$ which on signal executed by $S_1$, gets value $1.$ Now $S_2$ which is doing a wait on $a$ can continue execution making $a=0$;

Likewise this is followed for all other statements.

edited by
3 votes
3 votes
begin

S1;

          perbegin

           S3;

           begin

            S2;

                         perbegin

                          S4;

                          S5;

                          perend;

             end

             perend

end

begin

S7

                   perbegin

                    S4;

                    S5;

                   perend

end
1 votes
1 votes

Begin

Cobegin

begin S1:V(a) ; V(b) ; end

begin P(a):S2 ;V(c); V(d) ; end

begin P(b) : S3 ; V(e) ; end

begin P(c) : S4 ; end

begin P(d) : P(e) : S5 ; end

Coend

End

Begin

Cobegin

begin S6:V(f) ;V(g) ;end

begin P(f) : S4 ; end

begin P(g) : S5 ; end

Coend

End

edited by
0 votes
0 votes

begin:

      parbegin:

            begin:

                  S1;

                  parbegin:

                        S3; V(a);

                        begin:

                                S2;

                                parbegin:

                                     P(b); S4;

                                     P(a); P(b); S5;

                                parend

                          end

                    parend

               end

               S6; V(b);

       parend

​​​​​​​end

 

                        

Related questions

28 votes
28 votes
4 answers
2
Kathleen asked Sep 29, 2014
6,409 views
The details of an interrupt cycle are shown in figure.Given that an interrupt input arrives every $1$ msec, what is the percentage of the total time that the CPU devote...
28 votes
28 votes
3 answers
4
Kathleen asked Sep 29, 2014
13,079 views
Assume that the following jobs are to be executed on a single processor system$$\begin{array}{|c|c|} \hline \textbf{Job Id} & \textbf{CPU Burst Time} \\\hline \text{p} ...