synchronized (this[.classinfo]) in druntime and phobos
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed May 30 10:12:47 PDT 2012
On 5/30/12 9:23 AM, Alex Rønne Petersen wrote:
> On 30-05-2012 18:14, Andrei Alexandrescu wrote:
>> This is news to me. How do you publicly access the mutex of a
>> synchronized class object?
>
> Generally in two ways:
>
> 1) synchronized (obj)
This is not accessing the mutex for arbitrary operations.
> 2) obj.__monitor
All symbols starting with two underscores are reserved by the
implementation.
> (1) accesses it in order to actually do locking, but if obj is an
> instantiation of a class that uses the this reference internally for
> locking, you end up with potential deadlocks.
Deadlocks are endemic to mutex-based programming and are not avoided
inherently or preferentially by the alternative you discussed (exposing
unrestricted mutex).
> Therefore, you can say
> that obj's mutex is exposed.
Nothing could stop one, but that claim is incorrect.
Andrei
More information about the Digitalmars-d
mailing list