425 views
0 votes
0 votes

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.

a)Loading the count value into register from memory,

b)incrementing it in the register and

c)storing it back into the memory. as mentioned in the question as well

Consider 2 processes P1 and P2 calling tally() function in the main().Since they are parallel process we can imagine the two tally functions as concurrent processes P1 and P2.

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.This is a complex question as it requires very deep thinking as appropriate preemptions need to be taken and that too within the 3 - step implementation of incrementing count itself.I hope you get the point.
selected by

Related questions

1 votes
1 votes
2 answers
1
1 votes
1 votes
1 answer
2