how to cast away 'volatile'?

Andrew Haley aph@redhat.com
Wed Mar 14 12:57:00 GMT 2007


Matthew Woehlke writes:
 > Andrew Haley wrote:
 > > Matthew Woehlke writes:
 > >  > Andrew Haley wrote:
 > >  > > Michael Eager writes:
 > >  > >> It can also be used to share data between threads, but it becomes
 > >  > >> problematic if accesses are not atomic.  It's reasonable to use a
 > >  > >> shared volatile sig_atomic_t to communicate between threads, to say
 > >  > >> "I'm done" or "Start processing". 
 > >  > > 
 > >  > > Is that really safe, though?  There's nothing to stop the machine from
 > >  > > reordering memory writes, even if the compiler doesn't.
 > >  > 
 > >  > ...my understanding is that is exactly what 'fence' is for.
 > > 
 > > That's my understanding too.  Here, we're really talking about non-x86
 > > processors which have much weaker ordering guarantees.
 > 
 > On non-x86 processors I actually resort to pthread mutexes :-) (at least 
 > until/unless I have inline assembly implementations for those...)
 > 
 > So far no one has successfully answered my original question; how do I 
 > suppress these dang warnings? :-)

I did.  Maybe you didn't see it, or maybe you didn't like the
suggestion.

Andrew.



More information about the Gcc-help mailing list