useSameLockAs

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Nov 30 15:55:01 PST 2009


I'm thinking of adding a final method to Object:

final void useSameLockAs(Object another);

What it does is to make "this" give up on its own lock object and use 
the same lock as "another". Probably this may restrict implementations 
to some degree (e.g. I'm not sure how that would work with thin locks).

The advantage is that you can easily create lists, trees etc. that 
ostensibly use one lock per object, when they really all use only one 
lock, as the doctor prescribed.

The catch is that this only works well if the cost of recursive acquire 
(acquiring an already-acquired lock) is low enough. I haven't kept up 
with the relative costs; last time I looked recursive locks were still 
quite expensive, but I think the tradeoffs have changed a fair amount. 
Does anyone have some hard data?


Andrei



More information about the Digitalmars-d mailing list