Thin Lock Implementation

Brad Roberts braddr at bellevue.puremagic.com
Wed Aug 20 14:03:56 PDT 2008


On Wed, 20 Aug 2008, Bartosz Milewski wrote:

> dsimcha wrote:
> > Thin locks sounds pretty cool, but I do have one question.  It seems like
> > automatically inflating the lock the first time contention is detected is a
> > fairly
> > inefficient strategy, since the lock may be contested, but very
> > infrequently.
> > Would it be possible to keep track of the frequency of contesting and, if
> > the lock
> > is contested only, say, 1% of the time, just leave it as a spinlock?
> 
> The paper describing thin locks (my post has a link to it) claims that objects
> essentially come in two classes--the ones that are never contested, and the
> ones that are constantly contested. In-between situation are relatively rare.

I'll agree that inbetween is relatively rare, but just because there's 
contention, doesn't require the switch to heavy locks.  In a lot of the 
code I have written, one spin (assuming the spin utilizes rep; nop;) is 
sufficient for the 'blocked' acquire to finish it's acquire.  The use of 
heavy weight locks in that scenario is a net loss.

Later,
Brad



More information about the Digitalmars-d mailing list