October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Go Goroutines: What a Small Example Shows About Scheduling and Memory

A Go goroutine is not an OS thread, and concurrency does not guarantee parallelism or speed. Here’s what a tiny example can—and cannot—teach about CPUs, synchronization and memory.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A small Go example can make concurrency tangible: a go statement starts a goroutine, and the runtime schedules that goroutine on an operating-system thread. That does not mean Go creates one OS thread per goroutine, that the work runs in parallel, or that the program gets faster. The key is to see what the code demonstrates—and what it cannot prove without a measurement.

What a go statement actually starts

A goroutine is a function executing concurrently with other goroutines in the same process address space. In Go, the go keyword starts a function call as a goroutine. It is a unit of Go execution, not an operating-system thread.

As an Amazon Associate I earn from qualifying purchases.

The Go runtime schedules goroutines onto OS threads. A short example that starts goroutines therefore illustrates a request for concurrent work; it does not show that each request receives a dedicated kernel thread. Goroutines can take turns on an execution resource, and the runtime manages the mapping.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Concurrency is not the same as parallelism

Concurrency means multiple tasks can make progress during overlapping periods. Parallelism means tasks are executing at the same instant, typically on different processor cores. A program can be concurrent without being parallel.

Go’s GOMAXPROCS setting controls how many goroutines may execute Go code simultaneously. The runtime may use additional OS threads to handle goroutines blocked in system calls, so the setting is not a simple limit on the process’s total thread count. Its effective setting can vary by environment and Go version; do not infer a universal default from a tiny code sample.

Why doesn’t my program run faster with more CPUs?

More available CPUs help only when the program has independent work that can use them. If tasks depend on one another, spend much of their time waiting, or require frequent coordination, extra execution capacity may not improve elapsed time. For small tasks, the cost of starting work and communicating results can outweigh any benefit from parallel execution.

A code snippet can teach the mechanics of starting concurrent work, but it cannot establish a speedup by itself. That requires measuring a real workload under stated conditions and comparing equivalent runs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Shared data needs synchronization

Goroutines in one process can access the same memory. If multiple goroutines access shared data and at least one modifies it, the program must serialize those accesses. Go provides channels, mutexes and other sync tools, and atomic operations for this purpose.

A channel can coordinate goroutines, but merely having a channel somewhere in the program does not make every access safe. The relevant reads and writes must actually be ordered by synchronization. Unsynchronized concurrent access involving a write is a data race.

The Go Memory Model gives data-race-free programs sequentially consistent behavior: their outcomes are equivalent to an execution in which goroutines are multiplexed on a single processor. This is why a synchronization step in a small example matters as much as the goroutine launch.

“Do not communicate by sharing memory; instead, share memory by communicating.” — The Go Authors, Effective Go

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This is a design guideline, not a prohibition on shared memory. A mutex can be the clearest choice for some tasks; the important point is to make concurrent access safe and understandable.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Goroutine stacks are not the whole memory bill

Each goroutine has a stack that starts small and grows or shrinks dynamically as needed. The runtime documentation uses 2K as an example starting stack size; it is not a promise that every goroutine always costs exactly 2K, nor does it describe the memory use of an entire Go process.

Process memory also includes more than goroutine stacks. In particular, virtual memory reserved in a process’s address space is not the same as memory currently resident in physical RAM. The Go FAQ advises using resident-memory measures—such as RES on Linux or RSIZE on macOS—when assessing actual process memory use, rather than treating virtual-memory reservation as equivalent to physical usage.

How to read a tiny concurrency example

  • Look for the launch: a go statement starts a goroutine, not a guaranteed new OS thread.
  • Look for independence: separate goroutines can run in parallel only when the work and available execution resources allow it.
  • Trace shared reads and writes: check how channels, mutexes or atomics order access to shared data.
  • Measure before claiming speed: the code’s shape alone does not show whether concurrency improves performance.
  • Use the right memory measure: a stack-size example or virtual-memory figure is not the same as total resident process memory.

For loops that launch closures, Go version matters: the loop-variable behavior discussed in Effective Go applies to versions before Go 1.22. Check that the closure receives the intended value rather than assuming every loop iteration captures a distinct variable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Official Go references

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.