<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">That is built into the Iterator interface. </div><div dir="ltr"><br><blockquote type="cite">On Jul 4, 2023, at 4:05 AM, Alex Otenko <oleksandr.otenko@gmail.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="auto">How does the generator tell the consumer that no more values are forthcoming? </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 3 Jul 2023, 12:38 Robert Engels, <<a href="mailto:rengels@ix.netcom.com">rengels@ix.netcom.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="ltr"></div><div dir="ltr">Believe me. Queues are all you need there is no memory leak and no need to “close”. The producer side uses a weak reference to the queue. When there are no more strong references the producer side can terminate. </div><div dir="ltr"><br></div><div dir="ltr">You can’t use a standard blocking queue for this - but the queue implementation is fairly trivial - with a wake-up thread that listens on the weak reference queue. </div><div dir="ltr"><br><blockquote type="cite">On Jul 3, 2023, at 6:19 AM, Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com" target="_blank" rel="noreferrer">attila.kelemen85@gmail.com</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><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"><br>
2. We need to synchronize access to mutable state to avoid memory<br>
hazards. This is a separate issue from synchronizing access to<br>
mutable state to avoid correctness issues. With virtual threads on<br>
a single platform thread, this goes away too (because it's always<br>
the same thread observing memory operations; no barriers needed).<br><br></blockquote><div><br></div><div>That still seems incorrect to me (in principle, in practice it most likely will end up to be fine, but I just wouldn't rely on it), because the barrier is needed to prevent instruction reordering by the compiler, and you are not safe from that by using the same platform thread.</div></div></div>
</div></blockquote></div></blockquote></div>
</div></blockquote></body></html>