On Tue, 29 Oct 2024 08:29:55 GMT, David Holmes <dhol...@openjdk.org> wrote:

>> It's conceivable that in the future we might have more native methods we 
>> want to preempt.  Instead of enumerating them all, we could set a flag on 
>> the method.
>> 
>> I was assuming that David was suggesting we have the Java caller do a 
>> yield() or something, instead of having the native code call freeze.
>
> Yes. Instead of calling wait0 for a virtual thread we would call another 
> method `needToBlockForWait` that enqueues the VT in the wait-set, releases 
> the monitor and returns true so that caller can then "yield". It would return 
> false if there was no longer a need to block.

It's not that straightforward because the freeze can fail. By then we would 
have already started the wait call as a virtual thread though, not a platform 
thread. Maybe we could try to freeze before the wait0 call. We always have the 
option to use a flag in the method as Dean suggests instead of checking for a 
specific one. Since now there is only `Object.wait()` I think it's better to 
explicitly check for it.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21565#discussion_r1821391532

Reply via email to