Stage 1 · Code
Packages, Modules & Concurrency Intro
Goroutines
Start thousands of concurrent tasks with a single keyword, and coordinate them safely with sync.WaitGroup.
The go Statement
Prefixing a function call with go starts a goroutine — a lightweight concurrent task managed by the Go runtime. Goroutines are much cheaper than OS threads: you can start hundreds of thousands of them.
The Go runtime schedules thousands of goroutines onto a small pool of OS threads using cooperative and preemptive multitasking. A goroutine starts with just a few kilobytes of stack that grows as needed. Creating a goroutine costs almost nothing compared to creating a thread.
Goroutine Scheduling
Goroutines are multiplexed onto OS threads by the Go scheduler. When a goroutine performs a blocking operation (I/O, channel send/receive, system call), the scheduler runs another goroutine on that thread.
sync.WaitGroup
sync.WaitGroup is a counter you increment before starting work and decrement when work finishes. wg.Wait() blocks until the counter reaches zero.
Closures and Goroutines
A goroutine launched inside a loop that captures the loop variable captures the variable itself, not its current value. By the time the goroutine runs, the loop may have moved on.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.