[concurrency-interest] delaying in the nanosecond range
dl at cs.oswego.edu
Mon May 31 14:13:23 EDT 2010
On 05/31/10 13:42, Peter Veentjer wrote:
> Is there any way other than performing some arbitrary calculation (like
> calculating pi) to enter 0..1000 ns delay range?
The best other way is figure out something actually useful to do,
and do it! This is always worth exploring.
> I'm working on an STM and I'm including support for a bug shaker by
> inserting delays (delays are removed by the JIT if not enabled)
> at strategic positions. A park nanos leads to at least a few thousand
> nanoseconds delay and this causes new problems,
> like transactions not being able to complete because there always is
> some conflict.
Yes. Whenever there are no productive alternatives,
several j.u.c internals skip timed park calls below
a threshold (1-10 microsecs is reasonable) and instead spin more
on volatiles indicating completion, mixed with occasional
calls to Thread.yield, to heuristically nudge OS/VM to
try doing something else if it knows of anything.
See for example Exchanger.
More information about the Concurrency-interest