<div dir="ltr"><div dir="ltr">Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com">attila.kelemen85@gmail.com</a>> ezt írta (időpont: 2023. júl. 3., H, 10:58):<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"><div dir="ltr"><div dir="ltr">Robert Engels <<a href="mailto:rengels@ix.netcom.com" target="_blank">rengels@ix.netcom.com</a>> ezt írta (időpont: 2023. júl. 3., H, 1:58):<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"><div dir="auto"><div dir="ltr"></div><div dir="ltr">When you have virtual threads there is no need for generators - it is simply queues. The typical generator is simply implemented as a task that puts values on a queue with blocking semantics. The rest is syntactic sugar. </div><div dir="ltr"></div><blockquote type="cite"><div dir="ltr"><br></div></blockquote></div></blockquote><div><br></div><div>Though I never checked every detail on how virtual threads are implemented, but your claim looks to be false to me. Consider that you are implementing a normal `Iterator`, and then you don't read the iterator fully. In that case, your virtual thread will be sitting in the scheduler forever waiting to be unblocked, while this is not the case for reasonably implemented generators.</div></div></div></blockquote><div><br></div><div>After actually checking the relevant parts of the implementation, I would rephrase what I wrote above. While an unmounted thread in this case is not in any queue, your "start a virtual thread" solution could still lead to a memory leak. Also, I'm not sure if VT (and its stack) is considered to be a GC root or not. At least, it looks like the `delete` would never be called in `jvmtiEventController.cpp`. Also, creating an intermediate queue is probably less efficient than what the JVM can provide. Regardless, it still looks conceptually wrong to start a thread that might be alive forever.</div><div> </div></div></div>