why declaring with volatile code example
Example 1: Why volatile keyword is used for?
Using volatile Keyword is yet another way (like synchronized,
atomic wrapper) of making class thread safe. Thread safe
means that a method or class instance can be used by
multiple threads at the same time without any problem.
Example 2: volatile keyword in c
C's volatile keyword is a qualifier that is applied to a variable when it is declared. It tells the compiler that the value of the variable may change at any time--without any action being taken by the code the compiler finds nearby.