Girish Bal wrote:I am also getting 2200. Is there any scenario when the output can be 2100?
Try ...
1. First
thread sets x to three and goes to sleep.
2. Second thread sets x to two and goes to sleep.
3. First thread wakes up,
prints the two, and ... sets x to one and goes to sleep.
4. Second thread wakes up,
prints the one, and ... setx x to zero and goes to sleep.
5. First thread wakes up,
prints the zero, and exits the while loop and method.
6. Second thread wakes up,
prints the zero, and exits the while loop and method.
Hope this helps,
Henry