What is the volatile keyword useful for?

volatile has semantics for memory visibility. Basically, the value of a volatile field becomes visible to all readers (other threads in particular) after a write operation completes on it. Without volatile, readers could see some non-updated value. To answer your question: Yes, I use a volatile variable to control whether some code continues a loop. … Read more