[concurrency-interest] The code example in onSpinWait() Javadoc
aph at redhat.com
Sat Nov 16 04:15:53 EST 2019
On 11/15/19 3:55 PM, Roman Leventov wrote:
> I agree that Javadoc code shouldn't be a tutorial - that is why I also
> proposed to delete the example completely. But I think the current example
> is a little bit of anti-tutorial. To cite Josh Bloch - "Example code should
> be exemplary. If an API is used widely, its examples will be the archetypes
> for thousands of programs. Any mistakes will come back to haunt you a
> thousand fold."
So far all that you have done is assert that there is something wrong
with the example. I have seen nothing remotely convincing about what
is wrong with it. The example, as posted, shows exactly how the
intrinsic should be used in a spin loop.
Here you say:
> By "half-baked" I meant specifically that the example could be valid but
> only under specific conditions, such as core-pinned thread, or backoff
> timeout event, etc.
All code is only valid under specific conditions. This specific
condition is spinning, which should only be done for a short while
when you know that a lock is only held for a short while. Anybody who
wants to know the advantages and disadvantages of spinning can go to
the Wikipedia page https://en.wikipedia.org/wiki/Spinlock.
Andrew Haley (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the Concurrency-interest