The volatile keyword is used to inform the compiler that a class field may be modified by more than one thread in runtime at the same time. Therefore, the compiler will not perform any optimization about it assuming that it is accessed by a single thread. The idea is to ensure that when your code accesses the field, always the most up-to-date value will be retrieved.
You may use the volatile keyword with primitive types such as byte, bool, char, float, int, sbyte, short, uint and ushort, reference types and others.
When it is used with Boolean flags (and only with Booleans), the thread synchronization is not necessary once an atomic operation is executed when reading or writing the value. If you use with different types you cannot rely on the fact that is thread-safe.
The syntax is pretty straightforward as shown below:
private volatile bool _myFlag;