英文:
The Goroutines and the scheduled
问题
Go协程是协作调度的,而不是依赖内核来管理它们的时间共享。
英文:
i didn't understand this sentence plz explain me in detail and use an easy english to do that
Go routines are cooperatively scheduled, rather than relying on the kernel to manage their time sharing.
答案1
得分: 3
免责声明:这只是对内核和Go运行时中调度概念的粗略和不准确的描述,旨在解释概念,而不是对真实系统进行精确或详细的解释。
正如你可能(或者可能不)知道的那样,CPU实际上不能同时运行两个程序:CPU只有一个执行线程,每次只能执行一条指令。早期系统的直接结果是,你不能同时运行两个程序,每个程序都需要(系统层面上)一个专用线程。
目前采用的解决方案称为伪并行性:给定一定数量的逻辑线程(例如多个程序),系统将在一定的时间内执行一个逻辑线程,然后切换到下一个线程。使用非常小的时间间隔(大约是毫秒级),你给人类用户产生了并行性的错觉。这个操作称为调度。
Go语言并不直接使用这个系统:它自己实现了一个调度器,运行在系统调度器之上,并调度goroutine的执行,绕过为每个例程使用真实线程的性能开销。这种类型的系统称为轻量级/绿色线程。
英文:
Disclaimer: this is a rough and inaccurate description of the scheduling in the kernel and in the go runtime aimed at explaining the concepts, not at being an exact or detailed explanation of the real system.
As you may (or not know), a CPU can't actually run two programs at the same time: a CPU only have one execution thread, which can execute one instruction at a time. The direct consequence on early systems was that you couldn't run two programs at the same time, each program needing (system-wise) a dedicated thread.
The solution currently adopted is called pseudo-parallelism: given a number of logical threads (e.g multiple programs), the system will execute one of the logical threads during a certain amount of time then switch to the next one. Using really small amounts of time (in the order of milliseconds), you give the human user the illusion of parallelism. This operation is called scheduling.
The Go language doesn't use this system directly: it itself implement a scheduler that run on top of the system scheduler, and schedule the execution of the goroutines itself, bypassing the performance cost of using a real thread for each routine. This type of system is called light/green thread.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论