Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JDK9 Thread.onSpinWait() in spin locks #147

Closed
jvz opened this issue Dec 18, 2016 · 3 comments
Closed

Add support for JDK9 Thread.onSpinWait() in spin locks #147

jvz opened this issue Dec 18, 2016 · 3 comments

Comments

@jvz
Copy link

jvz commented Dec 18, 2016

For example, in BaseMpscLinkedArrayQueue (various places) or as a WaitStrategy, the new Thread.onSpinWait() method from JEP 285 would be useful to add support for. This method adds a JVM hint that it can use a PAUSE instruction in x86 (or equivalent) which is a lower power usage instruction useful for spin locks. Depending on implementation, this may take advantage of multi-release jars as accessing this method reflectively would defeat the purpose of it.

@vyazelenko
Copy link

@ivankrylov has created onSpinWaitMultiReleaseJar. From the README file:

This makefile builds a jar that works with and JDK from 6 to 9 (and beyond). Just add this jar to the classpath and insert ThreadHints.onSpinWait() whereever you have a busy loop.

@nitsanw
Copy link
Contributor

nitsanw commented Jul 11, 2018

The WaitStrategy is implemented by users, who can choose to implement it with onSpinWait if you like, there's nothing for JCTools to implement here.

@nitsanw nitsanw closed this as completed Jul 11, 2018
@franz1981
Copy link
Collaborator

@nitsanw I was thinking to introduce https://github.com/real-logic/agrona/blob/master/agrona/src/main/java/org/agrona/hints/ThreadHints.java#L31 to help in cases where spin 4 elements (it happens in many cases, including Dr. Yukov mpsc linked q port and others) right after the empty check, wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants