in Operating System
273 views
0 votes
0 votes
Consider the following code:

co-begin-end

     X=2;

   co begin

      X=X+3;

     X=X+1;

  co end

The final possible values of 'X' are:

a)3,5

b)3,4,5

c)3,5,6

d)5,3,2
in Operating System
273 views

1 Answer

1 vote
1 vote
ANY PROCESS OR STATEMENT B/W CO BEGIN AND CO END MEANS THAT THESE PROCESS/STATEMENT ARE CONCURRENT AND WE CAN START ANY STATEMENT AND FINISH IT IN ANY ORDER.

 now the   statement X=X+3 & X=X+1 contains 3 machine instruction each.For example both of them contain instruction

1. LOAD X,R    2. INCREMENT R   3.STORE R,X

LET FIRST STATEMENT BE X1 AND SECOND STATEMENT BE X2.

X1:1|X2:1,2,3|X1:2,3  (IN THIS CASE VALUE OF X WILL BE 5)

X2:1|X1:,1,2,3|X2:2,3(IN THIS CASE X WILL BE 3)

SERIAL SCHEDULING IS POSSIBLE THEN X=6 IS POSSIBLE.

SO ANSWER MUST BE 3,5,6 .
edited by

4 Comments

@Gurdeep Saini

Ok

I know the solution But not getting the procedure of @adarsh_1997 .

Can you elaborate ???

0
0
yes i can

if you run sequencial than you get 6

now expalaining this line

X1:1|X2:1,2,3|X1:2,3  (IN THIS CASE VALUE OF X WILL BE 5)

that load x,r by statement 1

now load inc and store by statement2  

now inc and store by statement you get 5

now you can understood second case
0
0
@kumar.dillip tell me brother which part?
0
0