Thin Lock Implementation
Bartosz Milewski
bartosz at relisoft.com
Tue Aug 19 16:01:38 PDT 2008
Sean Kelly wrote:
> If the "val = null" assignment is forgotten in makeLocal then an attempt
> to synchronize on c will throw a SharingException (or whatever it's
> called).
I would like to make the nulling of the original reference part of the
cast. In other words, makeLocal would take its argument by non-const
reference and null it. That still doesn't solve the problem of multiple
aliases, hence the need for SharingException.
> The benefit of being able to cast away the shared label is clearly for
> performance... if you know that you're the sole owner of a shared object
> then you don't need to lock for otherwise synchronized accesses (so
> long), much like assertUnique for const/invariant data.
There is one complication though--the type system. A function that takes
a non-shared argument can't be called with a shared object. But it's
true that a sharing cast is an optimization. The safe way to do it is to
make a thread-local deep copy of the object and pass that to a library
function. (Object cloning is a hot topic in D.)
More information about the Digitalmars-d
mailing list