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

Investigate the performance of Thread.yield() and Thread.sleep(long) usage #25

Open
alexjhawk opened this issue Aug 21, 2023 · 0 comments

Comments

@alexjhawk
Copy link
Collaborator

The performance of Thread.yield() and Thread.sleep(long) should be investigated.

Thread.yield() is intended to signal to the OS that the thread can be suspended and immediately re-added to the ready queue, allowing other threads to run.

  • The investigation should clarify whether the impact of Thread.yield() can result in indeterminate periods of delay, especially during scenarios where the other running threads may have a high-CPU load.

Thread.sleep(long) is intended to signal to the OS that the thread shall not run before the defined/specified time period has been met/passed. This is expected to be more predictable than Thread.yield() but still allow other threads to execute as necessary while the calling thread sleeps.

  • The investigation should clarify whether the impact of short Thread.sleep(long) calls can result in the thread not being suspended by the OS, which necessitates the original need to use Thread.yield() to force OS-level rescheduling.
    • If the sleep interval is increased, does this resolve the issue? Is it a feasible solution?

Reference:
[1]: https://www.java67.com/2012/08/difference-between-yield-and-sleep-in.html
[2]: https://stackoverflow.com/questions/1600572/are-thread-sleep0-and-thread-yield-statements-equivalent
[3]: https://github.com/kifferltd/open-mika/blob/079bcf51dce9442deee2cc728ee1d4a303f738ed/core-vm/java/java/lang/Thread.java#L699
[4]: https://github.com/kifferltd/open-mika/blob/master/core-vm/src/native/java/lang/Thread.c#L582

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

No branches or pull requests

1 participant