edited by
1,625 views
3 3 votes

2 Answers

3 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 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:
Position:
Show:

Related questions

0 0 votes
0 0 answers
816
816 views
Hopealways asked Dec 1, 2018
816 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 wrong.
0 0 votes
0 0 answers
852
852 views
Tuhin Dutta asked Oct 2, 2017
852 views
The pic shows the question along with options:
4 4 votes
1 answers 1 answer
1.7k
1.7k views
Pankaj Joshi asked Feb 1, 2017
1,678 views
Consider the following code used by the classical readers and writers.Note: rc = rc+1; will execute in 3 instructions like load, increment and then store.Which of the bel...