Monday, March 27, 2006

Volatile

The compilation system tries to reduce code size and execution time on all machines, by optimizing code. It is programmer responsibility to inform compilation system that certain code ( or variable ) should not be optimized.

A variable should be declared volatile whenever its value can be changed by something beyond the control of the program in which it appears, such as a concurrently executing thread.

Usage of volatile
1. An object that is a memory-mapped I/O port
2. An object variable that is shared between multiple concurrent processes
3. An object that is modified by an interrupt service routine
4. An automatic object declared in a function that calls jmpfunc and whose
value is-changed between the call to jmpfunc and a corresponding call to
topjmp

No comments: