Fully transitive const is not necessary

Sean Kelly sean at invisibleduck.org
Thu Apr 3 18:48:53 PDT 2008


== Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> Sean Kelly wrote:
> >> If C.name were invariant, there would be no need for any locks. I don't
> >> think this is a good example, because with D's invariant strings there
> >> is no need for such locking.
> > Also, I believe my example demonstrated that memory fences and order
> > of evaluation issues are still a concern with invariants.  They aren't a
> > magical safe ticket to lock-free programming land.
> While creating an invariant is something that should be done with care,
> once it is created, locks are no longer needed on it. After all, since
> it cannot change, where is the need to sync it?

The issue is largely with being sure that the creation process is complete
and the changes made appropriately visible by the time other threads
attempt to view the data.  Strings also impose an additional requirement
that any shared referencemust be set carefully because the references
are the size of two pointers and thus are not set in an atomic manner
even on x86.  My sample program illustrated both problems.  Sadly,
not even D's 'volatile' statement can do anything about safe setting of
string references, since the single instruction will still involve at least
two separate stores.


Sean



More information about the Digitalmars-d mailing list