search
Log In
23 votes
2.3k 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.

in Operating System
edited by
2.3k views
0
THEY ALSO HAVE TO WRITE THAT ALL SEMAPHORS ARE INTIALIZED TO ZERO.
0

Is this concept (parbegin and parend) there in the syllabus any more ?

4 Answers

20 votes
 
Best answer
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
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

3

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


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
2

@srestha  

 WHAT DO THEY MEAN BY PAREND AND PARBEGIN?

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

0
Same here @Deepanshu
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

13 votes
2 answers
1
1.3k 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 system, with main memory size equal to $4$ pages. Indicate the page references for which page faults occur for the following page replacement algorithms. LRU FIFO Assume that the main memory is initially empty
asked Sep 30, 2014 in Operating System Kathleen 1.3k views
20 votes
3 answers
2
3.3k views
Assume that the following jobs are to be executed on a single processor system ... Calculate the departure time (completion time) for job $p$ if scheduling is round robin with time slice $1$ $4$ $10$ $11$ $12$ None of the above
asked Sep 30, 2014 in Operating System Kathleen 3.3k views
17 votes
5 answers
3
12.8k views
Consider a system having m resources of the same type. These resources are shared by $3$ processes $A$,$B$, and $C$ which have peak demands of $3$, $4$ and $6$ respectively. For what value of m deadlock will not occur? $7$ $9$ $10$ $13$ $15$
asked Sep 30, 2014 in Operating System Kathleen 12.8k views
25 votes
2 answers
4
5.3k views
The root directory of a disk should be placed at a fixed address in main memory at a fixed location on the disk anywhere on the disk at a fixed location on the system disk anywhere on the system disk
asked Sep 30, 2014 in Operating System Kathleen 5.3k views
...