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

Switch to using high resolution timers #2

Open
dktapps opened this issue Oct 16, 2018 · 1 comment
Open

Switch to using high resolution timers #2

dktapps opened this issue Oct 16, 2018 · 1 comment
Labels
bug Something isn't working enhancement New feature or request

Comments

@dktapps
Copy link
Member

dktapps commented Oct 16, 2018

Recently it was discovered that system time changes during SleeperHandler->sleepUntil() will cause the sleeper to break. Changing the time forward causes the sleeper not to sleep at all for that call (which is OK), but changing the time backwards causes an extended sleep until the originally specified time, which has now moved into the future.

Example:

  • caller sleeps for now + 50,000 microseconds
  • system time changes back by 3 hours
  • sleeper handler now sleeps for 3 hours + 50,000 microseconds

This is undesirable for PocketMine-MP for obvious reasons.

Solutions:

  • use the HRTime extension (poorly documented, no git source code)
  • force an upgrade to PHP 7.3 to get access to the new hrtime() function
@dktapps dktapps added bug Something isn't working enhancement New feature or request labels Oct 16, 2018
@dktapps
Copy link
Member Author

dktapps commented May 4, 2021

I've attempted to implement this and arrived at the conclusion that providing an API like Threaded->wait(timeout) on SleeperHandler would be better for this purpose. This would shift the responsibility of deciding what kind of time measurement to use to the implementation, and Snooze would then not need to mess around calculating remaining sleep times.
This would make the API slightly more difficult to use, but since only PM uses this library anyway, I don't think that's a particularly big problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant