I learned the volatile keyword in Java. It serves as a mean to ensure visibility in other threads when a variable is written by one particular thread. It does this by removing machine caches of certain variables and disabling CPU instruction reordering under some cases at each write.
I noted that volatile exists in C++, while it serves different purposes. I wonder how C++ implements cache coherence and other things that goes with volatile in Java.