J
jacob navia
As far as I understood the standard, non-automatic variables
(static/global data) can't be cached in registers because in a
multiprocessing or multi-threading environment, another
thread/processor could read a wrong value from main
memory, if the compiler would do so
Even if the variable has local scope (static variable enclosed
in a function scope) this would still hold since another
processor/thread could run the same code at the same time
and read a wrong value from memory when the variable
lives in a register.
At each sequence point the compiler is supposed to present a
coherent view of memory, with all assignments stored into
main memory.
The standard says:
" At certain specified points in the execution sequence called
sequence points, all side effects of previous evaluations shall
be complete and no side effects of subsequent evaluations
shall have taken place."
This can be guaranteed in a multi-processing/multi-threaded
environment only for automatic variables, not globals
or static variables.
Is this reasoning correct?
jacob
(static/global data) can't be cached in registers because in a
multiprocessing or multi-threading environment, another
thread/processor could read a wrong value from main
memory, if the compiler would do so
Even if the variable has local scope (static variable enclosed
in a function scope) this would still hold since another
processor/thread could run the same code at the same time
and read a wrong value from memory when the variable
lives in a register.
At each sequence point the compiler is supposed to present a
coherent view of memory, with all assignments stored into
main memory.
The standard says:
" At certain specified points in the execution sequence called
sequence points, all side effects of previous evaluations shall
be complete and no side effects of subsequent evaluations
shall have taken place."
This can be guaranteed in a multi-processing/multi-threaded
environment only for automatic variables, not globals
or static variables.
Is this reasoning correct?
jacob