On Fri, 2003-07-25 at 16:58, Juhana Sadeharju wrote: > So, there is no "do not optimize away apperent volatile variables"? > Volatile variables in shmclient are easily recognized -- at least > I recognized them. It is the array variable which content is only > read but never written.
There is reason why optimizer chooses to keep variables in CPU registers instead of flushing all the stuff at every assignment operator. With current processors you would get _really_ slow code without careful optimizer use of register variables (btw. x86 arch has way too few registers available, compared to RISCs) and to be careful _not_ to trash the cache. Few points to keep in mind: 1) compiler doesn't know anything about threads (except those which support OpenMP), so any non-volatile variable is potential register variable which update time to other threads is unspecified. All inter-thread variables should be defined volatile. 2) compiler doesn't know anything about processes or IPC, so same as above. All inter-process variables should be defined volatile. 3) on SMP systems each CPU still has it's own dcache -- Jussi Laako <[EMAIL PROTECTED]>