The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+15 votes
1.1k views

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.

asked in Operating System by Veteran (59.6k points)
edited by | 1.1k views
0
THEY ALSO HAVE TO WRITE THAT ALL SEMAPHORS ARE INTIALIZED TO ZERO.

4 Answers

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

Par end

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 $s1$ there is no need of semaphore because it is the first one to execute.

Next $s2$ can execute only when s1 finishes. For this we have a semaphore a on which signal is executed by s$1$,which makes value of $a =1$. So, that $S2$ can execute after executing wait on a.making $a=0$;

Likewise this is followed for all other statements.

answered by Active (3.5k points)
edited by
+1
Hey bro..I think there is typo in the 3rd line ..we should write

P(a) S2 V(c) V(e)..

Like wise see further...

Make me correct if..I m wrong
0

Please Clarify this

+2

@krishn.jh  statements within parbegin-parend have no predefined order for execution. The answer is correct because wait() operation is performed on semaphores f and g, which guarantees that s4, s5 will execute after s6, because after execution of s6 only f and g are signaled.

+3 votes
begin

S1;

          perbegin

           S3;

           begin

            S2;

                         perbegin

                          S4;

                          S5;

                          perend;

             end

             perend

end

begin

S7

                   perbegin

                    S4;

                    S5;

                   perend

end
answered by Veteran (101k points)
+3
you have to use wait and signal constructs to ensure this order. Your answer is correct but is less parallel and not using semaphore.
0
signal and wait for cobegin and coend structure

not for parbegin and parend structure

right?
0 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

answered by Veteran (101k points)
edited by
0
You should combine all into one.S4 will do two down operations.similarly S5 will do 3 down operations.There is no need to have two being end blocks
+1

@srestha  

 WHAT DO THEY MEAN BY PAREND AND PARBEGIN?

MAYBE IT IS SILLY QUESTION . BUT I NEVER CAME ACROSS THIS CONCEPT

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

 

                        

answered by (325 points)

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,599 questions
48,601 answers
155,674 comments
63,742 users