[concurrency-interest] The code example in onSpinWait() Javadoc

Andrew Haley aph at redhat.com
Mon Nov 18 05:36:30 EST 2019


On 11/17/19 11:46 PM, Doug Lea via Concurrency-interest wrote:

> Usage may interact with GC, reference handling, and safepoints: in
> some contexts "a short while" isn't usually short, but we don't have
> a way of portably discussing such issues in javadocs. It's also one
> of the reasons we don't include a spinlock utility -- we cannot
> easily guess how best to write one that works well across enough
> usage contexts. (But we do make it easy to write them via tryLock.)

Sure, these ideas are hard to express if we restrict ourselves to
the mythical "write once, run anywhere" Java, but by the time we're
talking about writing our own spinlocks we're a long way from that.

"Everybody" ;-) knows that you should only spin for about (half?) the
same time as a simple system call, and that this is about 1000
iterations of a trivial loop. Intuitively this makes sense: you don't
want to make an (expensive) system call rather than just waiting for a
little while.

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the Concurrency-interest mailing list