A Minimal Go Loop Reveals How CPUs, Threads, and Memory Really Work

A developer running a near-empty infinite loop in Go observed surprising system activity — 100% CPU usage, 5 threads, 22,000 context switches, and over 400 GB of virtual memory — despite writing almost no code. The CPU spikes because the loop never blocks or sleeps, keeping the goroutine perpetually runnable and the processor constantly busy. The 5 OS threads were not created explicitly in the source code; they are part of the Go runtime's internal machinery, which manages goroutines, scheduling, memory, and garbage collection automatically. Above the Go runtime sits the OS scheduler, which arbitrates CPU access among all threads from every running process, causing the thousands of context switches observed. The experiment illustrates that a Go program is far more than its source code — the runtime and OS together handle the low-level work that developers never have to write themselves.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in