<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>
In other words, I'd like to be able to use a set of virtual threads<br>
that are guaranteed to be scheduled on a single platform thread.<br>
This is a common approach used inside language interpreters embedded<br>
into game engines (typically Lua, although I hear C# is seeing use for<br>
this too nowadays).<br>
<br>
Game engines and simulations tend to comprise a large number of<br>
concurrent tasks, and much of the time those tasks need to access<br>
complex mutable state that is very difficult to reliably make<br>
thread-safe. Additionally, most of the time it's desirable for it<br>
to be possible to pause and resume the execution of individual tasks.<br><br></blockquote><div><br></div><div>Even if you could specify that a set of virtual threads must run on the same platform thread, it would not solve your problem, because virtual threads are non-cooperative. So, even when there is only one underlying platform thread, you have to synchronize access to shared mutable state. In this regard virtual threads and platform threads are not fundamentally different (at least in principle). Though with continuation available you could solve your problem I believe.</div></div></div>