Launching Goroutines
go keyword, goroutine lifecycle and WaitGroups
What Is a Goroutine?
A goroutine is a lightweight, concurrently executing function managed by the Go runtime. Goroutines are much cheaper than OS threads — you can run thousands of them:
- Start with the
gokeyword - Initial stack ~2KB (grows dynamically)
- Scheduled by the Go runtime, not the OS
- Communicate via channels, not shared memory
The go Keyword
Prefix any function call with go to launch it as a goroutine:
package main
import ("fmt"; "time")
func greet(name string) {
fmt.Printf("Hello, %s!\n", name)
}
func main() {
go greet("Alice") // runs concurrently
go greet("Bob") // runs concurrently
time.Sleep(100 * time.Millisecond) // wait for goroutines
fmt.Println("done")
}All lessons in this course
- Launching Goroutines
- Unbuffered Channels
- Buffered Channels
- Channel Direction and Pipeline Patterns