Here comes the Loom, the concurrency will never be the same again

How does it work?

A simple view shows that multiple virtual threads (VT – green) are mapped to the Carrier thread(blue). It means a single carrier thread which works on an OS thread can manage a multiply number of Virtual threads.

It works in M:N model.


The virtual thread is not an atomic construct, but a composition of two concerns — a scheduler and a continuation..

Under the hood, everything is working on continuation and scheduler, without that virtual threads can’t work. Why? Because VT when it blocks have to be suspended (freeze) and restored (thaw) when the blocking operation is finished to continue doing logic.

Summary:

  • Lighter threads
  • Pay-as-you-go stacks (size 200-300 bytes) stored in a heap
  • Scales to 1M+ on commodity hardware
  • Clean stack traces
  • Your old code just works
  • Readable sequential code
  • The natural unit of scheduling for operating systems

In the next part of this article, I am going to describe more about it 🙂