Single Thread Continuation

Mark Raynsford org.openjdk at io7m.com
Mon Jul 3 11:08:54 UTC 2023


On 2023-07-03T12:58:42 +0200
Attila Kelemen <attila.kelemen85 at gmail.com> wrote:
>
> 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.

That's not a problem.

I've written several prototypes that do all of this with real platform
threads. The "cooperation" is simply implemented with semaphores and
other primitives. The main two problems with the prototypes are:

1. Platform threads are too heavyweight in terms of memory. We start up
   a few hundred tasks and we've already consumed nearly a gigabyte of
   memory. With virtual threads, this obviously goes away.

2. We need to synchronize access to mutable state to avoid memory
   hazards. This is a separate issue from synchronizing access to
   mutable state to avoid correctness issues. With virtual threads on
   a single platform thread, this goes away too (because it's always
   the same thread observing memory operations; no barriers needed).

-- 
Mark Raynsford | https://www.io7m.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: OpenPGP digital signature
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230703/a67e8dff/attachment.sig>


More information about the loom-dev mailing list