Virtual thread: Difference between revisions

Content deleted Content added
Line 48:
 
In order to support virtual threads efficiently, the language runtime has to be largely rewritten to prevent blocking calls from holding up an operating system thread assigned to execute a virtual thread<ref>{{Cite web |last=Szczukocki |first=Denis |date=2020-03-18 |title=Difference Between Thread and Virtual Thread in Java {{!}} Baeldung |url=https://www.baeldung.com/java-virtual-thread-vs-thread |access-date=2022-03-30 |website=www.baeldung.com |language=en-US}}</ref> and to manage thread stacks<ref>{{Cite web |date=2018-04-12 |title=Why you can have millions of Goroutines but only thousands of Java Threads |url=https://rcoh.me/posts/why-you-can-have-a-million-go-routines-but-only-1000-java-threads/ |access-date=2022-03-30 |website=rcoh.me |language=en-us}}</ref>. An example of a retrofit of virtual threads is Java Loom<ref>{{Cite web |title=Main - Main - OpenJDK Wiki |url=https://wiki.openjdk.java.net/display/loom/Main |access-date=2022-03-30 |website=wiki.openjdk.java.net}}</ref>. An example of a new language designed for virtual threads is Go<ref>{{Cite web |last= |first= |date=2022-03-22 |title=The Go Programming Language |url=https://go.dev/ |access-date=2022-03-30 |website=go.dev}}</ref>
 
== Complexity ==
Because virtual threads offer parallelism, the programmer needs to be skilled in multi-threaded programming and synchronization
 
Because a blocked virtual thread would block the OS thread it occupies at the moment, much effort must be taken in the runtime to handle blocking system calls. Typically, a thread from an pool of spare OS threads is used to execute the blocking call for the virtual thread so that the initially executing OS thread is not blocked
 
Management of the virtual thread stack requires care in the linker and short predictions of additional stack space requirements
 
== Implementations ==