<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">It doesn’t have to be with platform threads you could use virtual threads - its more the concept of using locks to simulate a cpu (and its scheduling) - i.e. all virtual tasks sharing a lock can essentially serialize their execution. E.g.<div class=""><br class=""></div><div class="">…</div><div class="">with cpuLock…</div><div class="">   acquire ioLock (per cpuLock)</div><div class="">   release cpuLock // allows other tasks to run on this cpu, but not perform IO</div><div class="">   perform IO</div><div class="">   acquire cpuLock // wait for other tasks to get to yield point</div><div class="">   release ioLock</div><div class="">end</div><div class=""><div class=""><br class=""></div><div class="">or similar - I’m sure you get the idea of how you can use locks to order the events.</div><div class=""><br class=""></div><div class="">If all of the lock contention is VT thread based it can be very efficient.</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Aug 21, 2024, at 8:54 AM, Rick Hendricksen <<a href="mailto:Rick.Hendricksen@vanderlande.com" class="">Rick.Hendricksen@vanderlande.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">Hi Robert,<o:p class=""></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">You mean using normal threads? We tried that years ago, and performance was awful.<o:p class=""></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class=""><o:p class=""> </o:p></span></div><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-US" class=""><o:p class=""> </o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="NL" class="">Best regards, / Met vriendelijke groet,<o:p class=""></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="NL" class=""> <o:p class=""></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class=""><span lang="EN-US" class="">Rick Hendricksen</span></b><span lang="EN-US" class=""><o:p class=""></o:p></span></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-US" class="">Specialist Software Engineering<o:p class=""></o:p></span></div></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""><o:p class=""> </o:p></span></div><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0cm 0cm;" class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class=""><span lang="EN-US" class="">From:</span></b><span lang="EN-US" class=""><span class="Apple-converted-space"> </span>robert engels <<a href="mailto:robaho@icloud.com" class="">robaho@icloud.com</a>><span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Wednesday, 21 August 2024 13:42<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Rick Hendricksen <<a href="mailto:Rick.Hendricksen@vanderlande.com" class="">Rick.Hendricksen@vanderlande.com</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>Alan Bateman <<a href="mailto:Alan.Bateman@oracle.com" class="">Alan.Bateman@oracle.com</a>>; <a href="mailto:loom-dev@openjdk.org" class="">loom-dev@openjdk.org</a>; Dennis van den Berg <<a href="mailto:Dennis.van.den.Berg@vanderlande.com" class="">Dennis.van.den.Berg@vanderlande.com</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: java.lang.ThreadBuilders and java.lang.ThreadBuilders.newVirtualThread() are not public<o:p class=""></o:p></span></div></div></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">To clarify, if you are guarding every possible blocking operation, you can easily implement your own continuations/scheduler with locks - you don’t need virtual threads. <o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 11pt; font-family: Calibri, sans-serif;">On Aug 21, 2024, at 6:36 AM, robert engels <<a href="mailto:robaho@icloud.com" style="color: rgb(5, 99, 193); text-decoration: underline;" class="">robaho@icloud.com</a>> wrote:<o:p class=""></o:p></p></blockquote></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""></o:p></div><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">If you’re doing this, instead of setting a variable - why not use a semaphore per logical cpu then you can run as many simulations in parallel across as many logical cpus as desired. <o:p class=""></o:p></div></div><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 11pt; font-family: Calibri, sans-serif;">On Aug 21, 2024, at 6:20 AM, Rick Hendricksen <<a href="mailto:Rick.Hendricksen@vanderlande.com" style="color: rgb(5, 99, 193); text-decoration: underline;" class="">Rick.Hendricksen@vanderlande.com</a>> wrote:<o:p class=""></o:p></p></blockquote></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class="Apple-converted-space"> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">Hi Alan,</span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">The way we identify simulation related blocking operations is by setting a variable right before parking the thread. The scheduler then checks if that variable is null or not, and if null it was not a simulation related blocking operation and we wait until we get a simulation related blocking operation. We can get away with this because we know we are running on a single thread.</span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">We agree that if the API would have a way to communicate the reason for parking the thread, that would be preferable to setting a variable before parking.</span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""> </span><o:p class=""></o:p></div><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-US" class=""> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="NL" class="">Best regards, / Met vriendelijke groet,</span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="NL" class=""> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class=""><span lang="EN-US" class="">Rick Hendricksen</span></b><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-US" class="">Specialist Software Engineering</span><o:p class=""></o:p></div></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""> </span><o:p class=""></o:p></div><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0cm 0cm;" class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class=""><span lang="EN-US" class="">From:</span></b><span lang="EN-US" class=""><span class="Apple-converted-space"> </span>Alan Bateman <<a href="mailto:alan.bateman@oracle.com" style="color: rgb(5, 99, 193); text-decoration: underline;" class="">alan.bateman@oracle.com</a>><span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Wednesday, 21 August 2024 11:17<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Rick Hendricksen <<a href="mailto:Rick.Hendricksen@vanderlande.com" style="color: rgb(5, 99, 193); text-decoration: underline;" class="">Rick.Hendricksen@vanderlande.com</a>>;<span class="Apple-converted-space"> </span><a href="mailto:loom-dev@openjdk.org" style="color: rgb(5, 99, 193); text-decoration: underline;" class="">loom-dev@openjdk.org</a><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>Dennis van den Berg <<a href="mailto:Dennis.van.den.Berg@vanderlande.com" style="color: rgb(5, 99, 193); text-decoration: underline;" class="">Dennis.van.den.Berg@vanderlande.com</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: java.lang.ThreadBuilders and java.lang.ThreadBuilders.newVirtualThread() are not public</span><o:p class=""></o:p></div></div></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div><table class="MsoNormalTable" border="0" cellpadding="0" width="100%" style="width: 721px; background-color: white;"><tbody class=""><tr class=""><td style="border: 1pt solid rgb(239, 123, 16); padding: 2.25pt;" class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; text-align: center;" class=""><strong class=""><span style="font-family: Calibri, sans-serif; color: rgb(239, 123, 16);" class="">Be aware</span></strong><span style="color: rgb(239, 123, 16);" class="">: This email was created outside of Vanderlande. Be cautious of its contents and<span class="Apple-converted-space"> </span><strong class=""><span style="font-family: Calibri, sans-serif;" class="">do not click</span></strong>any links or attachments unless you recognise the sender and know the content is safe.</span><o:p class=""></o:p></div></td></tr></tbody></table><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div><div class=""><p class="MsoNormal" style="margin: 0cm 0cm 12pt; font-size: 11pt; font-family: Calibri, sans-serif;"> <o:p class=""></o:p></p><div class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On 21/08/2024 09:13, Rick Hendricksen wrote:<o:p class=""></o:p></div></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">Hi Alan,</span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">Thanks for taking the time to help us with this issue.</span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">We see three problems with using the default scheduler with maxPoolSize:</span><o:p class=""></o:p></div><ol start="1" type="1" style="margin-bottom: 0cm; margin-top: 0cm;" class=""><li class="MsoListParagraph" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="en-NL" class="">Other virtual threads which are not directly related to the simulation would slow down the simulation</span><o:p class=""></o:p></li><li class="MsoListParagraph" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="en-NL" class="">Running multiple simulations in parallel would not be possible</span><o:p class=""></o:p></li></ol></blockquote><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">In that case, parallelism means several VMs, each running with maxPoolSize=1, rather than running several simulations in the same VM at the same time.<br class=""><br class=""><br class=""><br class=""><br class=""><o:p class=""></o:p></div><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div><ol start="3" type="1" style="margin-bottom: 0cm; margin-top: 0cm;" class=""><li class="MsoListParagraph" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="en-NL" class="">We need full control over which thread runs, and how to treat yield. If the thread is yielding because of a simulation-related blocking operation, we want to run the next thread. If it’s yielding due to IO, we don’t want to switch to another thread. If IO wait would result in a yield, that would be unpredictable, and would affect the result of our simulation.</span><o:p class=""></o:p></li></ol><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class=""> </span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="en-NL" class="">It would be very helpful for us if custom schedulers would be exposed. Could you tell us more about the explorations you mentioned? And is it an option to take our use case into account there?</span><o:p class=""></o:p></div><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class=""> <o:p class=""></o:p></div></blockquote><div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">There are two explorations at this time. One is allowing the scheduler be selected at virtual Thread create time, like the prototype API on the builder that was in EA builds for a long time but didn't get any feedback. One of the use-cases for this is servers that want to use their own event loop thread as a carrier to avoid hand-off. The other exploration is exposing a way to replace the system-wide scheduler for servers that want to manage their own thread pool rather than use a work stealing scheduler. We talked about this a bit at JVMLS 2024, I think the recordings will be posted soon.<span class="Apple-converted-space"> </span><br class=""><br class="">Note that the problem space and the possible interface for custom schedulers is larger than might initially seem. You touched on exposing the "reason" for preemption and that is one of several things that a scheduler may need to be notified of. One thing that would be useful to know from your experiments is how you distinguish between your "<span lang="en-NL" class="">simulation-related blocking operation" and the dozens of other possible cases where a thread may be preempted.</span><br class=""><br class="">In any case, the summary on this topic is that it is being explored again but proceeding with great caution.<br class=""><br class="">-Alan<o:p class=""></o:p></div></div><div class="MsoNormal" align="center" style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; text-align: center;"><hr size="3" width="100%" noshade="" align="center" style="color: rgb(239, 123, 16);" class=""></div><p class=""><span style="font-size: 9pt;" class="">** Disclaimer **<o:p class=""></o:p></span></p><p class=""><span style="font-size: 9pt;" class="">This e-mail, including any attachments, may include proprietary and confidential information of Vanderlande and may only be read by the person or those persons to whom it is addressed.<span class="Apple-converted-space"> </span><br class="">This document is forwarded to you in such a form (e-mail) that Vanderlande cannot guarantee the completeness and/or correctness of its contents and information.<span class="Apple-converted-space"> </span><br class="">If you have received this e-mail message in error, please notify us immediately.<span class="Apple-converted-space"> </span><br class="">Please also delete this document from your computer.<span class="Apple-converted-space"> </span><br class="">This document may not be reproduced, copied, distributed, published, modified, or furnished to third parties, without the prior written consent of Vanderlande.</span></p></div></blockquote></div></blockquote></div></div></blockquote></div><br class=""></div></div></body></html>