[concurrency-interest] adaptive spinning/biased lockingand java.util.concurrent.lock

David Holmes davidcholmes at aapt.net.au
Tue Jun 30 20:18:25 EDT 2009


Can I also clarify something about biased-locking as I recently encountered
some very mis-guided perceptions of what it is. :)

Biased-locking exists to make un-needed synchronization as cheap as
possible. It works on the assumption that objects are not shared, so locks
are not contended and so aren't in fact needed. So when an object acquires a
monitor lock it simply does a fast-lock by CAS'ing in the owning thread's Id
into the object header. But the release of the lock is almost a no-op, it
leaves the object "locked" by that original thread. Subsequent locks by that
thread then don't need the (expensive) CAS. If another thread tries to lock
the object we go through an expensive bias-revocation process and revert to
using normal locking - the fact that contention occurred shows biasedlocking
is not applicable to this object.

As Doug says you don't tend to use j.u.c Locks in circumstances where
biased-locking would be beneficial.

Cheers,
David Holmes

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Doug Lea
> Sent: Wednesday, 1 July 2009 6:52 AM
> To: Peter Veentjer
> Cc: concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] adaptive spinning/biased lockingand
> java.util.concurrent.lock
>
>
>
> Peter Veentjer wrote:
> > Hi Guys,
> >
> > do modern jvm's also provide adaptive spinning and biased locking for
> > the lock implementations (especially the reentrantlock) in the
> > java.util.concurrent.locks package or is this only provided for the
> > intrinsic lock?
> >
>
> Only intrinsics. Biased locking does not work well
> for locks that you expect to contend, which are among
> the typical cases for using ReentrantLock. We might
> someday want to automate adaptive spinning in
> ReentrantLock and other AQS locks. However, this is
> less pressing an issue than it is for in intrinsic locks,
> since you can always use tryLock-based constructions
> to increase spinning.
>
> -Doug
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest




More information about the Concurrency-interest mailing list