Redirected
edited by
959 views
4 votes
4 votes

edited by

1 Answer

Best answer
3 votes
3 votes
Minimum value of count is 2.Here u have to assume that increment or decrement operation is a series of three step.Loading the count value into register from memory,incrementing it and storing it back into the memory.

Consider 2 processes P1 and P2 calling test() function in the main(). Each process performs 5 iterations.Let R1 and R2 be the respective registers for storing the value of count. Initially count = 0 . P1 starts the execution . It uses the 2 steps of incrementing count in the first iteration as mentioned earlier . So R1 value = 1 . But count = 0 still since value of R1 is not stored.

Then we preempt P1 and we run 4 iterations of P2 and performing all the 3 steps of incrementation in each iteration. Then we preempt P2 and store the value of R1 in count and 1st iteration is over. Count value = 1

.Now we preempt P1 and run 1st 2 steps of final iteration in P2.So count value will be incremented to 2 and hence content of R2 = 2. But now we preempt and run the 2nd to 5th iteration of P1. With this P1 execution is over and finally we store the value of count from R2. So final value of count = 2. With this P2 also gets completed. Hence minimum possible value of count is 2 with this approach.
selected by

Related questions

2 votes
2 votes
3 answers
1