synchronized (this[.classinfo]) in druntime and phobos
Dmitry Olshansky
dmitry.olsh at gmail.com
Tue May 29 05:29:07 PDT 2012
On 29.05.2012 16:26, Alex Rønne Petersen wrote:
> 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.
>
Agreed, awfuly crippled design for a language with Thread-local by default.
Looks like we have 'oh my god, what were they thinking' moment here.
If anything I'd rather re-implement the whole v-table infrastructure via
mixins, templates & friends.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list