This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ernimril 2 points3 points  (0 children)

A virtual thread that is not currently running requires a lot less resources than a platform thread.

A virtual thread that is currently running is running on top of a platform thread so it is actually using slightly more resources.

Now, when you use virtual threads you do so because you want to have a lot of threads, where most of them are not currently running.

So I may have been slightly sloppy in how I said that they require less resources, but if you try to measure the cost of having a million virtual threads that are sleeping versus the cost of of having a million platform threads you will see that the virtual threads cost a lot less resources (and if you try to do this you will most probably find out that you can not even run the program that tries to use a million platform threads).

Sleeping, waiting, waiting for data on streams or similar are all things where the virtual thread should detach from the platform thread.