volatile variable in C++

The volatile keyword specifies that the value associated with the name that follows can be modified by actions other than those in the user application. Therefore, the volatile keyword is useful for declaring objects in shared memory that can be accessed by multiple processes or global data areas used for communication with interrupt service routines.
When a name is declared as volatile, the compiler reloads the value from memory each time it is accessed by the program. This dramatically reduces the possible optimizations. However, when the state of an object can change unexpectedly, it is the only way to ensure predictable program performance.
The precise meaning of volatile is inherently machine dependent and can be understood only by reading the compiler documentation. Programs that use volatile usually must be changed when they are moved to new machines or compilers.
According to the C++11 ISO Standard, the volatile keyword is only meant for use for hardware access; do not use it for inter-thread communication. 
For inter-thread communication, the standard library provides std::atomic<T> templates.
```
#include <csignal>
#include <iostream>
using namespace std;

volatile sig_atomic_t gSignalStatus;

void signal_handler(int signal) {
  gSignalStatus = signal;
}

int main() {
  signal(SIGINT, signal_handler);

  cout << "SignalValue: " << gSignalStatus << endl;
  cout << "Sending signal " << SIGINT << endl;
  raise(SIGINT);
  cout << "SignalValue: " << gSignalStatus << endl;
}
```