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

Jonathan Pryor jonpryor at vt.edu
Wed Feb 18 19:18:17 EST 2004


Below...

On Wed, 2004-02-18 at 18:09, Carl Witty wrote:
<snip/>
> > 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.

I am reasonably sure this works.  At least, this is generally what most
books on threading that I've read have recommended.

Furthermore, the C++ standard I have, in section 1.9 (Program execution)
has the following statements:

        7.  Accessing an object designated by a volatile lvalue (3.10),
        modifying an object, calling a library I/O function, or calling
        a function that does any of these operations are all side
        effects, which are changes in the state of the execution
        environment...  At certain specified points in the execution
        sequence called sequence points, all side effects of previous
        evaluations shall be complete and no side effects of subsequent
        evaluations shall have taken place.  [Sequence points occur
        after every complete statement.]
        
        ...
        
        11.  The least requirements on a conforming implementation are:
                - At sequence points, volatile objects are stable in the
                sense that previous evaluations are complete and
                subsequent evaluations have not yet occurred.
                ...

This would imply to me that my understanding is correct, but I haven't
written a compiler, so I could be wrong.

 - Jon





More information about the Mono-devel-list mailing list