Mahbub Rahman wrote:@Henry,
Thanks for the nice idea. But if the variable is static, than Thread-0 should also print 2. How do you think?
I also thought just like you did, but the confusion is the variable is static.
Am I missing something?
Just because the variable is static doesn't mean the everything is in sync with it. Take this expression...
Yes, The id variable will be increment, but then it has to do the rest of this expression...
And do it before, it is sent for printing. It only reads and increment the id variable once, and then while it needs to calculate all the components of the expression, it has to do it with temporary variables.
Henry