This is the mail archive of the 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]
Other format: [Raw text]

Re: Heads-up: volatile and C++

Gabriel Dos Reis <> writes:

| Richard Henderson <> writes:
| | On Thu, Apr 14, 2005 at 11:30:20PM +0200, Jason Merrill wrote:
| | > Consider Double-Checked Locking
| | > (
| | > I used DCL with explicit memory barriers to implement thread-safe
| | > initialization of function-local statics
| | > (libstdc++-v3/libsupc++/  The proposed change to volatile
| | > semantics would allow me to write it more simply, by just making the
| | > initialized flag volatile.  Yes, volatile would be stronger than is
| | > actually necessary for DCLP, but I don't have to use it if I want
| | > finer-grained control over the synchronization.
| | 
| | Is there any reason to want to overload volatile for this, rather than
| | 
| |   template<classname T> T acquire(T *ptr);
| |   template<classname T> void release(T *ptr, T val);
| | 
| | where the functions do the indirection plus the memory ordering?
| My understanding what that some compilers may do "speculative register
| promotion". 
| (I think the example given by Hans actually involved lock()/unlock()
| not acquire/release).

Jason (seating next to me) just pointed out to me that "volatile" did
not appear in the example shown by Hans -- as I mistakenly thought.

So ignore my message.  Sorry for the confusion.

-- Gaby

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