Can continuation support finally solve the "How do I stop this thread" problem?
Sam Pullara
spullara at gmail.com
Mon Sep 5 06:44:47 UTC 2022
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.
On Fri, Sep 2, 2022 at 2:34 PM Ron Pressler <ron.pressler at oracle.com> wrote:
> I don’t think all OS operations have non-blocking alternatives (at least
> before io_uring), but Alan will know more.
>
> 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.
>
> — Ron
>
> On 2 Sep 2022, at 19:28, Archie Cobbs <archie.cobbs at gmail.com> wrote:
>
> On Fri, Sep 2, 2022 at 11:52 AM Ron Pressler <ron.pressler at oracle.com>
> wrote:
>
>> > 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?
>>
>> 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.
>>
>
> 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 :)
>
> On UNIX at least, AFAIK all blocking operations have a non-blocking
> alternative, so *in theory* 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 (link
> <https://www.gnu.org/software/pth/pth-manual.html#standard_posix_replacement_api>)
> and use setcontext/getcontext to context switch.
>
> 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.
>
> -Archie
>
> --
> Archie L. Cobbs
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20220904/725b8b27/attachment-0001.htm>
More information about the loom-dev
mailing list