Rahul Ba wrote:I was thinking because, each thread keeps copy variable which is not shared to any other thread. i.e
When multiple threads using the same variable, each thread will have its own copy of the local cache for that variable. So, when it's updating the value, it is actually updated in the local cache not in the main variable memory.
Each thread does have its own copy of the variable. And each copy of the variable is in main memory (different memory, of course).
And since each thread is setting its own copy of the varible to 10, before printing it, it is safe to assume that "10" is always printed.
Henry