liveBook · Manning

Hybrid threading system

As explained in Learn Concurrent Programming with Go

A hybrid threading system combines user-level execution units with multiple kernel-level threads that the operating system schedules.

A hybrid threading system combines lightweight user-level execution units with multiple kernel-level threads. In Go, goroutines run through runtime-managed queues attached to kernel threads, allowing work to use multiple processors instead of remaining on one operating-system thread. section 2.3.2

The model works through several cooperating layers:

  • M:N mapping connects M goroutines to N kernel-level threads, rather than mapping every goroutine directly to an operating-system thread. section 2.3.2
  • Each kernel thread manages a queue of goroutines, so multiple kernel threads can execute goroutines on separate processor cores. section 2.3.2
  • When a goroutine blocks on I/O or work becomes unbalanced, the runtime can create or reuse another thread and move work through work stealing. section 2.6

Inspecting available parallelism

A small Go program can print the number of logical processors and the current GOMAXPROCS setting. The runtime normally initializes GOMAXPROCS from NumCPU(), while calling GOMAXPROCS with a value below one reports the current setting without changing it. For example, execution may print “Number of CPUs: 8” and “GOMAXPROCS: 8.”

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains M:N mapping, processor use, blocking behavior, and work stealing, while deferring runtime implementation details.
Examples
Uses CPU-count inspection, GOMAXPROCS output, and a blocking-I/O scenario involving work stolen by another kernel thread.
What it assumes
Contrasts processes, kernel-level threads, and user-level threads while assuming basic familiarity with operating-system scheduling.
What you can do after
Evaluate Go’s available parallelism by inspecting NumCPU and GOMAXPROCS and understanding runtime responses to blocking or imbalance.
How it connects
Connects goroutines with user-level threads, kernel-level threads, work stealing, concurrency, parallelism, and process scheduling.

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.