Go Runtime: Difference between revisions
Line 12: | Line 12: | ||
==Goroutine Management== | ==Goroutine Management== | ||
{{Internal|Go_Language_Goroutines#Goroutines_and_the_Go_Runtime|Goroutines and the Go Runtime}} | {{Internal|Go_Language_Goroutines#Goroutines_and_the_Go_Runtime|Goroutines and the Go Runtime}} | ||
=Memory Management and Garbage Collection= | |||
{{Internal|Go_Language_Memory_Management_and_Garbage_Collection|Memory Management and Garbage Collection}} |
Revision as of 20:42, 16 January 2024
Internal
Overview
Go Runtime Scheduler
The Go runtime scheduler manages all goroutines that are created and need processor time. It binds operating system threads to logic processors, which, in turn, execute goroutines. As goroutines are created, they are placed in the scheduler's global run queue. From there, they are added to a logical processor's run queue and executed. Depending on the scheduling algorithm, a running goroutine can be stopped and rescheduled at any time. When a goroutine makes a blocking system call, the scheduler will detach the thread from the processor and create a new thread to service that processor. When a goroutine makes a network I/O call, the goroutine is detached from the logical processor and moved to the runtime network poller. Once the poller indicates a read or write operation is ready, the goroutine is assigned back to a logical processor to handle the operation.
Logical Processor
Go logical processors execute goroutines. Each logical process is individually bound to a single operating system thread.
SetMaxThreads
The Go runtime limits each program to a maximum 10,000 threads by default. This value can be changed by setting SetMaxThreads
in runtime/debug
package.