in Operating System edited by
851 views
3 votes
3 votes

in Operating System edited by
851 views

3 Comments

Ans:2 ?
0
0
2 ??
0
0
question samaj nhi aaya. koi explain kro kya krna hai ismai??
0
0

2 Answers

3 votes
3 votes
Ans : 2

Initially count = 0

Suppose P1 and P2 are two processes started parallelly.

P1 : i=1 Read count = 0; increment by 1 and pre-empt (Here count=1; not yet written).

P2 : i=1 Read count = 0; increment by 1; write count = 1

P2 : i=2 Read count = 1; increment by 1; write count = 2

P2 : i=3 Read count = 2; increment by 1; write count = 3

P2 : i=4 Read count = 3; increment by 1; write count = 4 and pre-empt.

P1 : Write count = 1 and pre-empt.

P2: i=5 Read count = 1; increment by 1 and pre-empt (Here count=2; not yet written)

P1 : i=2 Read count = 1; increment by 1; write count = 2

P1 : i=3 Read count = 2; increment by 1; write count = 3

P1 : i=4 Read count = 3; increment by 1; write count = 4

P1 : i=5 Read count = 4; increment by 1; write count = 5

P1 completed.

P2 : Write count = 2

P2 completed.

Final value of count is 2.

1 comment

why p1 written at the last of execution???
0
0
0 votes
0 votes

Initial Count = 0

P1 enters in fn and read count = 0;

P1 increment and preempt before write back 

P2 enters in function and read count =0

Preempt P2 after incrfement

P1 write back count =1 ;

P2 also write count =1

Answer is 1

3 Comments

What about for loop in tally() ?

0
0

Forgot about loop .

Then how you got Answer is 2 

I am getting answer as 5 .

0
0
I answered :)
0
0
Answer:

Related questions