RFR: 8305092: Improve Thread.sleep(millis, nanos) for sub-millisecond granularity [v3]
David Holmes
dholmes at openjdk.org
Wed Apr 19 13:17:48 UTC 2023
On Wed, 19 Apr 2023 09:51:48 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> src/hotspot/os/posix/os_posix.cpp line 1545:
>>
>>> 1543:
>>> 1544: int PlatformEvent::park_nanos(jlong nanos) {
>>> 1545: assert(0 <= nanos, "nanos are in range");
>>
>> `nanos` should never be zero else you call the untimed park.
>
> OK, I see how is that guaranteed in the Windows case. In POSIX case, calling `park()` is untimed wait, but `park(0)` is converted to absolute time that is already passed, and so `pthread_cond_timedwait` would return immediately, right? So `park(0)` is not equivalent to just `park()`? Still, the strongest behavior from Windows case takes precedence here. Changed the assert.
Posix is missing the assertion that Windows has, but if you check the callers you will find we never pass 0. The typical pattern is:
if (millis <= 0) {
self->_ParkEvent->park();
} else {
self->_ParkEvent->park(millis);
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13225#discussion_r1171323075
More information about the core-libs-dev
mailing list