edited by
819 views
3 votes
3 votes

edited by

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

Answer:

Related questions

0 votes
0 votes
0 answers
1
Hopealways asked Dec 1, 2018
418 views
In these type of questions “Will we NOT consider CONTEXT SWITCHING unless mentioned???”If context switching is ALLOWED, minimum value will be 8...Correct me if I’m ...