Content deleted Content added
Haraldrudell (talk | contribs) |
Haraldrudell (talk | contribs) |
||
Line 19:
The term Virtual threads has been used ambiguously over the years. For example Intel<ref>{{Cite web |title=Intel Technology Journal |url=https://www.intel.com/content/dam/www/public/us/en/documents/research/2007-vol11-iss-4-intel-technology-journal.pdf}}</ref> in 2007 spoke about their hyper-threading as virtual threads. Virtual threads were commercialized with Google’s Chrome browser in 2008<ref>{{Cite web |title=Threading and Tasks in Chrome |url=https://chromium.googlesource.com/chromium/src/+/HEAD/docs/threading_and_tasks.md#core-concepts |access-date=2022-04-05 |website=chromium.googlesource.com}}</ref> where virtual threads may hop physical threads. Virtual threads are truly virtual, created in user-space software
# Virtual Threads can hop over all processors and cores▼
## This allows for using all available hardware, a 10x increase on today’s computers▼
## In the go1.18 implementation, there are virtual thread queues per execution unit. There are additional virtual threads not allocated to an execution unit and an execution unit can steal virtual threads from another execution unit<ref>{{Cite web |last=Lu |first=Genchi |date=2021-07-22 |title=Java’s Thread Model and Golang Goroutine |url=https://medium.com/@genchilu/javas-thread-model-and-golang-goroutine-f1325ca2df0c |access-date=2022-04-05 |website=Medium |language=en}}</ref>▼
## Unlike coroutines, if a virtual thread is in an infinite loop, it does not block the program. Execution continues at a higher cpu load, even if there are more looping threads than available execution units▼
# Today’s implementations of Virtual Threads have smaller, managed stacks▼
## This allows for many magnitudes more threads than from using OS threads▼
# Because allocating a virtual thread is akin to allocate memory structures, they can be allocated very quickly, like 600,000 per second. This is not possible for OS threads and would crash the host▼
## The quicker ramp-up lessens the need for thread-pools of pre-launched threads to cater for sudden increases in traffic▼
# Like OS threads, virtual threads share memory map and can therefore freely share and access memory objects subject to synchronization. Data can be shared as zero-copy references▼
▲
* '''Virtual threads require no yield or similar interventions by the programmer'''
▲
*# Go 1.18 can have approximately 350,000 virtual threads with less than 3 KiB stack per gigabyte of main memory, ie at least 15 million on a 2021 consumer-grade computer
*# A consumer grade computer typically supports 3,000 OS threads an can through system configuration offer maybe 15,000
* '''Virtual Threads can be allocated quickly'''
▲
▲
* '''Virtual threads share memory map like OS threads'''
▲
** Some single-threaded architectures, such as the V8 ECMAScript engine used by Node.js, do not readily accept data that the particular thread did not allocate, requiring special zero-copy data types to be used when sharing data between threads
* '''Virtual threads offer parallelism like OS threads'''
** Parallelism means that multiple instructions are executed truly at the same time which typically leads to a magnitude of faster performance
** The simpler concurrency, in which a single resource is shared in small time increments so that it appears always available, is easier to implement and program but do not offer any gains in performance
== Implementations ==
=== Google Chrome Browser ===
Virtual threads are used to serialize singleton input/output activities. When a virtual thread is executing, it can hop on different OS thread. The Chrome browser first appeared in 2008
=== Go ===
goroutines became preemptive with go1.4 in 2014 and is since the most prominent application of virtual threads. Go first appeared in 2009
=== Java Project Loom ===
[https://openjdk.java.net/projects/loom/ Project Loom]: ''Virtual threads'' is a lightweight user-mode scheduled alternative to standard OS managed threads. Virtual threads are mapped to OS threads in a many-to-many relationship. Work on project loom by Oracle started in 2017. Loom has the goal of implementing virtual threads for performance, at the same time simplifying thread handling across OS threads, concurrent threads and virtual threads
== See also ==
|