<div dir="ltr">I've always thought that the restrictions were somewhat ridiculous considering that an interrupt could happen at almost any time with an OOM. Basically no one protects against that. Perhaps you have the same rule where folks can say that the entire process should die on a thread kill (like can be set for OOM)? Unblocking blocked calls should be the easiest part of fixing this and not even that interesting relative to worrying about losing synchronization.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 2, 2022 at 2:34 PM Ron Pressler <<a href="mailto:ron.pressler@oracle.com">ron.pressler@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div style="overflow-wrap: break-word;">
I don’t think all OS operations have non-blocking alternatives (at least before io_uring), but Alan will know more.
<div><br>
<div>Also, for a problem to be worth fixing, it needs to be sufficiently troublesome. I don’t think many servers will run into such issues. The most common operations in servers are network operations and those don’t block OS threads, and uncommon
 operations are smoothed over by the scheduler.</div>
<div><br>
</div>
<div>— Ron<br>
<div><br>
<blockquote type="cite">
<div>On 2 Sep 2022, at 19:28, Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank">archie.cobbs@gmail.com</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div dir="ltr">On Fri, Sep 2, 2022 at 11:52 AM Ron Pressler <<a href="mailto:ron.pressler@oracle.com" target="_blank">ron.pressler@oracle.com</a>> wrote:<br>
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> So what happens when a virtual thread invokes X? Isn't that going to "lock up" the underlying platform thread (or whatever) while X is blocked?<br>
<br>
Yes, and that’s what happens for most filesystem operations. We will employ io_uring, where available, to use non-blocking filesystem operations, but until then (or where io_uring is not available) we compensate by adding more OS threads to the scheduler because
 there’s nothing the user can do to avoid it (see JEP 425). User-mode threads/coroutine implementations in other languages also suffer from this limitation. User-mode code can only work within the confines of the APIs provided by the OS.<br>
</blockquote>
<div><br>
</div>
<div>OK thanks, now I get it. This limitation inherited from the OS is not going to be eliminated or worked around by the new code. So if I create 1,000,000 virtual threads and they all call some blocking operation then I'm probably in trouble :)<br>
</div>
<div><br>
</div>
<div>On UNIX at least, AFAIK all blocking operations have a non-blocking alternative, so
<i>in theory</i> it would be possible to make everything unblockable, but of course all internal code - including any JNI native code - would have to play along (i.e., be rewritten to use some official system call wrapper API). This would be similar
 to what the Pth user-mode threading library does, where they wrap all of the blocking system calls with non-blocking versions (<a href="https://www.gnu.org/software/pth/pth-manual.html#standard_posix_replacement_api" target="_blank">link</a>) and
 use setcontext/getcontext to context switch.<br>
</div>
<div><br>
</div>
<div>There are lots of languages (e.g., lua) that have the same issue - everything is coroutines, rainbows, and unicorns until some native code somewhere calls read(2) or waitpid(2) or whatever. It would be cool if someday Java was the one language
 platform that was able to finally fix this, but that's obviously a lot easier said than done. I'm not suggesting doing this, just pointing out that it's possible.</div>
<div><br>
</div>
<div>-Archie<br>
</div>
</div>
<br>
-- <br>
<div dir="ltr">Archie L. Cobbs<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>

</blockquote></div>