This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

question on volatile


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]