Back to Concepts Roadmap
🟤 Level 7 — Runtime & Concurrency
Concurrency

The GMP Scheduler Model

Inside the Go runtime M:N scheduler: Goroutines (G), Machines (M), and Processors (P).

Real-World Analogy (Mental Model)

A restaurant kitchen: G = Customer Orders (Goroutines), P = Cooking Stations with work queues, M = Chefs/Cooks (OS Threads) executing recipes.

Key Concepts & Rules To Remember

  • G (Goroutine), M (OS Thread), P (Logical Context bound to GOMAXPROCS CPU cores).
  • Work-stealing: idle Processors steal goroutines from busy processors to balance load.
  • Sysmon runtime thread preempts long-running goroutines cooperatively.
Step-by-Step Code

1. Understanding The GMP Scheduler Model

Inside the Go runtime M:N scheduler: Goroutines (G), Machines (M), and Processors (P). In Go, the gmp scheduler model is designed around clarity and high runtime efficiency.

example.goGo 1.24+
// GOMAXPROCS sets number of P contexts (defaults to CPU core count)
runtime.GOMAXPROCS(runtime.NumCPU())

Common Beginner Pitfalls & Mistakes

Mistake: Misusing the gmp scheduler model without understanding its memory or concurrency semantics.
✅ Correct Way: Always follow standard Go idioms and verify with tests.
Self Assessment

Knowledge Check

Verify your understanding with these interactive practice questions.

Quizzes

Quick checks for understanding

Multiple-choice with inline explanations—expand to see why.

What is the primary concept behind The GMP Scheduler Model?

Finished this lesson?

Mark it as complete to track your overall Go mastery.