I was reading about volatile in java and here there is a nice explanation http://tutorials.jenkov.com/java-concurrency/volatile.html.
It says that volatile is good in situations...
where only Thread 1 writes to the shared counter variable, declaring the counter variable volatile is enough to make sure that Thread 2 always sees the latest written value.
volatile int counter = 0;
But when both Threads, Thread1 writes (counter++) to the volatile and Thread2 reads the volatile at the same time, Thread2 might get counter as 0. (Getting counter as 1 it would mean that Thread2 would wait for Thread1 to write but atomicity doesn't exist in volatile or Thread1 is slighty faster than Thread2. Ideally lets say they both the same)
So what is the point of volatile in this situation?