I have a very basic question: Can the operating system scheduler context switch between user-level threads mapped to kernel level?
Assume that goscheduler schedules a goroutine A on the kernel thread. Now goroutine A makes a sysblock call, who does the context switch first: the OS or the go scheduler?
The Go scheduler manages goroutines, which are reused on operating system-level threads. The Go scheduler can efficiently perform context switches between Goroutines, such as when a Goroutine makes a blocking system call, without involving the OS scheduler. However, it is important to note that due to factors such as time slicing, the operating system scheduler may independently interrupt and perform context switches. Therefore, the exact timing of a context switch and the involvement of the operating system scheduler may not be accurately determined from the Go program's perspective.
Further reading:
Go Scheduler: Implementing a lightweight concurrency language
The above is the detailed content of Golang context switching. For more information, please follow other related articles on the PHP Chinese website!