RFR: 8338383: Implement JEP 491: Synchronize Virtual Threads without Pinning [v7]
Alan Bateman
alanb at openjdk.org
Mon Oct 28 09:21:57 UTC 2024
On Mon, 28 Oct 2024 00:26:31 GMT, David Holmes <dholmes at openjdk.org> wrote:
>> When we unmount on a timed-wait call we schedule a wakeup task at the end of `afterYield`. There are two mechanisms that avoid the scheduled task to run and wake up the virtual thread on a future timed-wait call, since in this call the virtual thread could have been already notified before the scheduled task runs. The first one is to cancel the scheduled task once we return from the wait call (see `Object.wait(long timeoutMillis)`). Since the task could have been already started though, we also use `timedWaitSeqNo`, which the wake up task checks here to make sure it is not an old one. Since we synchronize on `timedWaitLock` to increment `timedWaitSeqNo` and change state to `TIMED_WAIT` before scheduling the wake up task in `afterYield`, here either a wrong `timedWaitSeqNo` or a state different than `TIMED_WAIT` means there is nothing to do. The only exception is checking for `SUSPENDED` state, in which case we just loop to retry.
>
> Thanks for the explanation but that needs to be documented somewhere.
The comment in afterYield has been expanded in the loom repo, we may be able to bring that update in.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21565#discussion_r1818670426
More information about the nio-dev
mailing list