0PricingLogin
Go Academy · Lesson

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 go keyword
  • 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

  1. Launching Goroutines
  2. Unbuffered Channels
  3. Buffered Channels
  4. Channel Direction and Pipeline Patterns
← Back to Go Academy