Home > Backend Development > Golang > Golang context switching

Golang context switching

WBOY
Release: 2024-02-06 09:10:08
forward
876 people have browsed it

Golang 上下文切换

Question content

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?


Correct answer


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:

proc.go in golang source code

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template