This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
question on volatile
- To: egcs at egcs dot cygnus dot com
- Subject: question on volatile
- From: Martin Kahlert <martin dot kahlert at mchp dot siemens dot de>
- Date: Fri, 5 Nov 1999 11:29:51 +0100
Hi,
i have ran into a problem while programming threads:
If i write something like this:
for(i=0;i<nthreads; i++)
{
Arguments[i].start = 1;
Arguments[i].end = 42;
Arguments[i].runme = 1;
}
how can i be sure, that the compiler doesn't compile
it into something like that:
for(i=0;i<nthreads; i++)
{
Arguments[i].runme = 1;
Arguments[i].start = 1;
Arguments[i].end = 42;
}
Background of the question:
I want to use a polling wait, no conditional variables/mutexes.
Is it enough to make the runme field inside Arguments volatile?
I.e. does a write/read of a volatile variable ensure that the complete
code in front of it was already executed or does it only mean
that the compiler can't optimize it away completely?
These things should be common problems in hardware driver writing, so
the compiler should provide some mechanism for it.
Thanks for any hints,
Martin.