A goroutine is an independently running concurrent function. Prefix a function call with go to schedule it concurrently; ordinary function syntax otherwise stays the same. Goroutines are lightweight, so Go can run very large numbers without requiring a traditional thread pool. section 1.4.1 section 1.10
Start concurrent work
A web crawler can launch separate crawls without changing the crawl function itself: go crawl("...") go crawl("...") Each call runs in its own goroutine while the work inside crawl remains sequential. section 1.4.1
Figure 1.3 The go statement before a function spawns a new goroutine that runs the given function concurrently. This figure illustrates running the crawl function concurrently in two separate goroutines.
The diagram shows how placing go before a function call spawns separate concurrent executions of that function. section 1.4.1
Goroutines abstract operating-system threads. The Go scheduler multiplexes them onto threads, parks a goroutine that blocks on a channel or I/O operation, and runs another ready goroutine. Their small, adjustable stacks and user-space scheduling reduce the cost of concurrent work, though the scheduler’s full internals are beyond this overview. section 1.4.2
Use goroutines with an explicit communication and lifecycle plan:
- Send data, tasks, and results through channels when goroutines need to communicate or synchronize; channel operations can pause goroutines to coordinate stages. section 1.4.3
- Remember that goroutines share memory: channels do not provide memory isolation, so shared memory still requires correct use. section 1.4.3
- Use worker goroutines for concurrent HTTP load, and use a monitoring goroutine to close an output channel only after workers finish. section 6.9
A practical use appears in HTTP servers: net/http runs a registered Handler’s ServeHTTP method in a separate goroutine for each request. This works efficiently because the scheduler multiplexes goroutines onto operating-system threads. section 8.3






