[Mono-devel-list] Thread safety of readonly data members?

Carl Witty cwitty at newtonlabs.com
Wed Feb 18 18:09:02 EST 2004


On Wed, 2004-02-18 at 14:46, Jonathan Pryor wrote:
> <snip what="double checked locking example"/>
> 
> > > In C++, you could use code similar to the above, and you WOULD NOT need
> > > to lock both the class constructor and the accessor methods, as the
> > > calling code ensures that the class has properly constructed before
> > > invoking any member functions.
> 
> I forgot to mention this, but in C++ the static member would also need
> to be declared as "volatile" for double-checked locking to properly
> work, IIRC.

Are you sure this works?  This would require that compilers for some
platforms (at least for Alpha) put memory-barrier instructions around
accesses of volatile variables; I'd check to make sure that this really
happens before relying on double-checked locking with that compiler.

Carl Witty







More information about the Mono-devel-list mailing list