Ephemeral threads
Alan Bateman
alan.bateman at oracle.com
Sat Jan 10 15:42:52 UTC 2026
On 10/01/2026 11:04, Andrew Haley wrote:
> :
>
> Maybe it's waiting on some kind of semaphore that has become
> unreachable. In that case, the thread cannot make any progress. It
> makes no difference whether you GC it or not. The native resources it
> holds will never be released. Semantically, an unreachable thread is
> not a thing: it has no properties.
>
> Therefore, any thread that is unreachable may be GC'd, surely.
>
> I guess I may be missing some way that an unreachable thread is
> observable? If so, what is it?
>
Diagnosing resource leaks, semaphore permit "leaks" etc. is much harder
if threads can be GC'ed before they terminate.
We looked into the implications of ephemeral threads a few years ago.
Aside from being fragile to use, they lead to issues that range from
mildly spooky to truly horrifying. Think of cleaners running when
objects are in inconsistent state. Think of objects with finalizers that
put a "goodbye" element to a queue and cause a thread to come back from
the dead. There's a lot more to this. The summary is that introducing
ephemeral threads has huge implications due to the interactions with so
many parts of the system. We decided not to spend further time on it.
-Alan
More information about the loom-dev
mailing list