WALID BELRHALMIA
WALID BELRHALMIA

Reputation: 441

The Goroutines and the scheduled

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.

Upvotes: 0

Views: 640

Answers (1)

Elwinar
Elwinar

Reputation: 9499

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.

Upvotes: 3

Related Questions