Original question - Click here
My question is how deadlock is possible in that question. I've read the discussion and folks are saying that this below line is not an atomic execution, fair enough!! And more than one process can have same t[i] value and can stuck at while loop mentioned later in original question, but i don't understand how to processes can get same t[i] value?
pmax (t[0],....,t[n-1])+1; c[i]=0;
And this line can broken down as
- LOAD R0, MAX
- INCREMENT R0
- STORE T[i], R0
Now say P0 comes and execute line 1 and got value R0 = 0 and then at line 2) R0 = 1 and now say P0 preempted.
Now P1 comes and execute line 1 and 2 and got R1 or R0 = 0 and got preempted, but if you preempt this P1 also, then what process will further execute and if you don't preempt P1 then P1 will have t[1] = 1.
So, how two processes has same t[i] value at any time?