Is a volatile int in Java thread-safe?
Yes, you can read from it and write to it safely – but you can’t do anything compound such as incrementing it safely, as that’s a read/modify/write cycle. There’s also the matter of how it interacts with access to other variables. The precise nature of volatile is frankly confusing (see the memory model section of … Read more