synchronized (this[.classinfo]) in druntime and phobos

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed May 30 11:25:03 PDT 2012


On 5/30/12 10:28 AM, Alex Rønne Petersen wrote:
> On 30-05-2012 19:12, Andrei Alexandrescu wrote:
>> 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.
>
> No, it is indeed not. You didn't explicitly say you wanted to do
> "arbitrary operations", so I assumed that by accessing the mutex you
> meant doing the only two things that are sensible for a mutex: Locking
> and unlocking it. What else would you want to do?

For example, locking it in one function and unlocking it in another. 
This is impossible with synchronized(obj).

To summarize, the synchronized(obj) operation is not exposing the mutex, 
only manipulate it in a specific way.


Andrei


More information about the Digitalmars-d mailing list