On 20/08/2017 6:37 AM, Martin Buchholz wrote:
Future projects:

377 * <li>The specified amount of real time has elapsed, more or less.

Replace with

* <li>At least the specified amount of real time has elapsed.

(I think I failed to persuade David last time ...)

And you will continue to do so. :) In the presence of spurious wakeups it is completely untestable to say "at least the specified time has elapsed". It also frees the VM of the burden of having to deal with operating systems that have primitives that themselves return early (aka spuriously) or which act that way when in "broken" virtualization environments.

Cheers,
David

---

We should add a @see to TimeUnit.timedWait which at least deals with excessNanos.

---
What percentage of the jdk's wait loops are actually correct?
Especially if you throw in the requirement to only call System.nanoTime after checking the condition the first time.
Wait loops should probably not call currentTimeMillis.
Writing a good timed wait loop is surprisingly tricky.
Condition.awaitNanos helps by returning the updated time to wait.  See our competing code snippet:
http://download.java.net/java/jdk9/docs/api/java/util/concurrent/locks/Condition.html#awaitNanos-long-

Maybe the code snippet should use the plain millis form, since the excess nanos are pretty much useless this decade.

Reply via email to