liveBook · Manning

Go runtime

As explained in Learn Concurrent Programming with Go

The Go runtime is the standard execution environment that manages Go program services such as goroutine scheduling.

The Go runtime manages goroutines above the operating-system thread level, providing a lightweight execution model that uses fewer resources than OS threads. section 2.3

Rather than mapping every goroutine directly to a kernel thread, it uses M:N threading: many goroutines are distributed across a set of kernel-level threads. This lets concurrent work use multiple processors when available. section 2.3.2

The runtime coordinates concurrent execution by:

  • Maintaining queues of goroutines for kernel-level threads to execute. section 2.3.2
  • Allowing multiple kernel-level threads to run on separate processor cores. section 2.3.2
  • Keeping work moving when a goroutine blocks on I/O by creating or reusing another thread and redistributing work. section 2.3.2

Inspecting available parallelism

A small program can print runtime.NumCPU() and runtime.GOMAXPROCS(0). For example, it may report eight CPUs and a GOMAXPROCS value of eight. Calling GOMAXPROCS with a value below one reads the current setting without changing it. section 2.3.2

Figure 2.9 User-level threads executing within a single kernel-level thread

A figure showing user-level threads executing within a single kernel-level thread makes the runtime’s layered execution model concrete. section 2.3.2

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains lightweight threads, M:N mapping, processor use, runtime queues, and I/O blocking, without detailing the complete scheduler implementation.
Examples
Uses CPU-count inspection, GOMAXPROCS output, goroutine queues, and I/O-blocking work redistribution as concrete runtime examples.
What it assumes
Assumes basic Go familiarity while introducing user-level threads, kernel-level threads, and goroutines as the execution model.
What you can do after
Evaluate how goroutines can scale across available processors and remain productive during blocking I/O.
How it connects
Connects goroutines with channels, user-level threads, kernel-level threads, operating-system threads, I/O blocking, and processor cores.

Also explained in

Compare how 2 books explain Go runtime →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Concurrent Programming with Go. The section links point to the parts of the book it draws on.