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

deadalnix deadalnix at gmail.com
Tue May 29 08:35:56 PDT 2012


Le 29/05/2012 14:26, Alex Rønne Petersen a écrit :
> On 29-05-2012 14:19, Dmitry Olshansky wrote:
>> On 29.05.2012 16:07, Regan Heath wrote:
>>>
>>> According to the docs here:
>>> http://dlang.org/class.html#synchronized-functions
>>>
>>> A synchronized function locks "this" and as "this" is exposed
>>> publicly... In the following code the "lock" statement and "synchronized
>>> void bar" lock the same mutex.
>>>
>>> class Foo {
>>> synchronized void bar() { ...statements... }
>>> }
>>>
>>> void main()
>>> {
>>> Foo foo = new Foo();
>>> lock(foo)
>>> {
>>> ...statements...
>>> }
>>> }
>>>
>>>> But locking on another class rather than something specifically
>>>> intended as a mutex does seem to me like it's asking for trouble.
>>
>> I'd be darned but every Object in D has monitor fields. If I'm not
>> mistaken it's the mutex you are looking for ;)
>>
>>
>
> Indeed they do, and therefore each object must eat an entire word of
> memory for questionable gain.
>
> Generalized object monitors is the worst idea in programming language
> and virtual machine design, ever.
>

Every fucking things MUST BE AN OBJECT :D So let's lock on ANY OBJECT !


More information about the Digitalmars-d mailing list