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

Avoid System.currentTimeInMillis in concurrent library, use System.nanoTime #7546

Closed
scabug opened this issue Jun 1, 2013 · 2 comments
Closed
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jun 1, 2013

For example scala.concurrent.SyncVar uses currentTimeMillis in method waitMeasuringElapsed which is used in method get. This can result in quite long waits if system-clock is changed meanwhile. Get-method description clearly states that parameter is timeout, which is not related to current system-clock time in any way.

Using system-clock time in any concurrent libraries, except in cases where that is the specific purpose, is quite confusing and easily results in frozen processes when time is set backwards (or something happens too soon, if set forwards)

In general, it seems that using System.nanoTime() in all cases should be the norm as it does not suffer from above. There is almost never the case where one is interested in time elapsed in system-clock time, compared to actual stop-watch/wall-clock time. The wrapping of nanotime in every 292 years seems to be quite small price to pay comparared to relatively frequent system-clock change. Also all parameters could be defined as nanoseconds for added granularity.

For clarity, scala core should define nanotime as standard way to be used in all delays, waits, timeouts, etc. e.g. by introducing it in Predef with clear documentation, perhaps also starting it from zero (e.g. private val start = System.nanoTime(); def now() { System.nanoTime() - start }).

@scabug
Copy link
Author

@scabug scabug commented Jun 1, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7546?orig=1
Reporter: Jani Räty (jraty)
Affected Versions: 2.10.1, 2.11.0-M3

@scabug
Copy link
Author

@scabug scabug commented Dec 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants