recategorized by
9,808 views
29 29 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.

6 Answers

Best answer
36 36 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
5 5 votes
begin

S1;

          perbegin

           S3;

           begin

            S2;

                         perbegin

                          S4;

                          S5;

                          perend;

             end

             perend

end

begin

S7

                   perbegin

                    S4;

                    S5;

                   perend

end
1 1 vote

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 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

 

                        

Position:
Show:

Related questions

20 20 votes
2 answers 2 answers
10.0k
10.0k views
Kathleen asked Sep 29, 2014
10,030 views
The following page addresses, in the given sequence, were generated by a program:$\text{1 2 3 4 1 3 5 2 1 5 4 3 2 3}$This program is run on a demand paged virtual memory ...
40 40 votes
5 answers 5 answers
10.7k
10.7k views
Kathleen asked Sep 29, 2014
10,731 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...
37 37 votes
6 answers 6 answers
27.9k
27.9k views
Kathleen asked Sep 29, 2014
27,894 views
A certain moving arm disk storage, with one head, has the following specifications:Number of tracks/recording surface $= 200$Disk rotation speed $= 2400$ rpmTrack storage...
20 20 votes
2 answers 2 answers
4.4k
4.4k views
go_editor asked Feb 5, 2018
4,390 views
The following relations are used to store data about students, courses, enrollment of students in courses and teachers of courses. Attributes for primary key in each rela...