<html class="apple-mail-supports-explicit-dark-mode"><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">Using a LinkedTransferQueue as the backing structure gives the same result. </div><div dir="ltr"><br><blockquote type="cite">On Jan 16, 2026, at 4:05 AM, Alex Otenko <oleksandr.otenko@gmail.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="auto">Because a push iterator isn't the same as a generator.<div dir="auto"><br></div><div dir="auto">The code interacting with a generator is like two threads joined with a 0 capacity queue.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, 13 Jan 2026, 10:17 Remi Forax, <<a href="mailto:forax@univ-mlv.fr">forax@univ-mlv.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:#000000"><div>It starts to be off topic,</div><div>but it's not clear to me that in Java we want to map a generator to an iterator and not to stream (a push iterator with a cleanup semantics).</div><div><br></div><div>regards,</div><div>Rémi</div><div><br></div><hr id="m_-1445927055581229218zwchr"><div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"Alex Otenko" <<a href="mailto:oleksandr.otenko@gmail.com" target="_blank" rel="noreferrer">oleksandr.otenko@gmail.com</a>><br><b>To: </b>"Alan Bateman" <<a href="mailto:alan.bateman@oracle.com" target="_blank" rel="noreferrer">alan.bateman@oracle.com</a>><br><b>Cc: </b>"loom-dev" <<a href="mailto:loom-dev@openjdk.org" target="_blank" rel="noreferrer">loom-dev@openjdk.org</a>><br><b>Sent: </b>Tuesday, January 13, 2026 10:28:13 AM<br><b>Subject: </b>Re: [External] : Re: Ephemeral threads<br></blockquote></div><div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="auto">Yes, I understand that now that's not easy to do in Java. I just don't think it's all that exotic, and certainly not a bug. After all, we've all written at least one iterator when we did a coding interview.<div dir="auto"><br></div><div dir="auto">There is 1:1 correspondence between the iterators and the generators. So if we can GC the iterators without special dance, we should be able to do that for the generators. You could see an iterator as an explicit declaration that you are not going to use any features that rely on there being a finally - no unlocking, no resource management outside of what a finalizer can achieve, no peer to coordinate with, etc. Likewise an explicit declaration by an engineer that this here piece of code entering a wait is perfectly fine to GC, doesn't seem all that different.</div><div dir="auto"><br></div><div dir="auto">Yes, in general there are thread semantics, try-finally, reference loops and other obstacles - but we don't need to solve a general case, just the one that is in 1:1 correspondence with the iterators.</div><div dir="auto"><br></div><div dir="auto">I understand that there may be safe ways to implement the same with the existing mechanisms - like, the user of the generator might wrap the interaction in a try-with-resource, and that way control the lifecycle explicitly. </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 13 Jan 2026, 08:00 Alan Bateman, <<a href="mailto:alan.bateman@oracle.com" target="_blank" rel="noreferrer">alan.bateman@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 13/01/2026 06:42, Alex Otenko wrote:<br>
><br>
> I think there are plenty of designs with generators, iterators and <br>
> async where non-termination is not a bug.<br>
<br>
That is true is some other languages/runtimes. If Java were to add <br>
generators or some other exotic control flow in the future then there <br>
would be more spooky issues to work through, some of which overlap with <br>
the spooky issues that have come up in the discussion here.<br>
<br>
-Alan<br>
</blockquote></div><br></blockquote></div></div></div></blockquote></div>
</div></blockquote></body></html>