abc def foo bar
abc def foo bar

Reputation: 2398

How does Go decide when to context switch between goroutines?

I am curious as to how the Go language schedules goroutines. Does it switch only during channel requests and I/O or does it have a periodic coroutine switching loop?

Upvotes: 6

Views: 2947

Answers (1)

Emil Vikström
Emil Vikström

Reputation: 91963

Go does not have a preemptive scheduler yet, but one is planned for 1.2. So no, Go will not switch context during CPU-only calculations, only during I/O (reading from memory is also considered I/O if it isn't in a register already). You can read some discussion about it in Issue 543 - preemptive scheduling.

Upvotes: 8

Related Questions