liveBook · Manning

M:n threading

As explained in Learn Concurrent Programming with Go

An M:N threading model maps M user-level threads to N kernel-level threads.

M:N threading maps M user-level threads, such as Go goroutines, onto N kernel-level threads. Multiple kernel threads can run concurrently on multiple processors while user-level work remains lightweight. section 2.3.2

Go assigns kernel threads local run queues and maintains a global queue for unassigned goroutines. When a goroutine blocks on I/O, the runtime can create or reuse another thread and move work. section 2.3.2

Checking processor availability

runtime.NumCPU reports available logical processors, while runtime.GOMAXPROCS(0) reports the current processor limit. For example, both may print 8 on an eight-core system.

How Learn Concurrent Programming with Go covers it

How deep it goes
Explains mappings, processor selection, local and global queues, blocking, and work stealing, but omits runtime implementation details.
Examples
Uses two processor cores, local and global run queues, an I/O-blocked thread, and a Go CPU-count inspection listing.
What it assumes
Assumes basic familiarity with threads and processors while defining goroutines, M:N mapping, queues, and GOMAXPROCS.
What you can do after
Evaluate Go’s goroutine scheduling using NumCPU and GOMAXPROCS, and interpret queue behavior during parallel execution and I/O blocking.
How it connects
Contrasts M:N threading with N:1 threading and connects it to goroutines, kernel threads, run queues, I/O blocking, and work stealing.

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.