Imagine EVs that came out, but instead of using a wheel, you used a joystick. Sure they're more efficient, better for the ecosystem, but you do have to switch to using a joystick.
Then someone comes out with a EV that uses a steering wheel and pedals.
That's the thing. You can keep thinking in only threads, and only details, but whomever passes the executor to you decides. So you build your code to work with an executor, tasks and assuming that things have thread-access. But you are able to assume there's millions of threads, so you don't have to worry about locking them away and preventing things from running (something that sometimes you have to be aware of when running sync code inside an async function running on a thread pool).
I am saying they are, it let's you work with just threads but still keep things hybrid, but unlike threads virtual threads don't use a full stack and thread structure, but keep a small lightweight task system like async functions.
Implementation wise there should be no improvement or degrading between async and virtual threads. It's just the advantages of a simpler, more versatile way to write threading code.
Much better. The big problem with async/await is that it basically forces you to infect your whole codebase with it. You have to sprinkle it everywhere and gods help you if you call blocking function by an accident. Have fun scrutinising every external library to figure out if it does not do some blocking IO (for example resolving a DNS name) somewhere deep in its guts.
Even .net standard library had to create a double of pretty much every IO related method as SomethingAsync.
2
u/stronghup Sep 29 '22 edited Sep 29 '22
The cool thing is "Virtual threads are fully compatible with the existing `Thread` API, " .
You can have your cake and eat it too.
But is this really better than async/await?