Essentially, Operating System runs threads, which runs your code. The Go’s trick is that compiler inserts calls into Go runtime in various places, e.g. sending a value thru the channel, making a call to runtime package), so that Go can notify scheduler and take action.

https://pkg.go.dev/runtime


Goroutines

Goroutines are **user-space threads. **

Now, the OS can schedule and manage threads, but it’s overhead to the OS, considering the properties that threads carry. That’s why the Go scheduler handles the goroutines, and it basically multiplexes the goroutines on the OS threads.

https://www.velotio.com/engineering-blog/understanding-golang-channels

What blocks is the goroutines, but not the OS thread

This is very neat… it’s a really handful optimization choice!


🌱 Back to Garden