Skip to content

Concurrency Exercises

Practice goroutines, channels, and concurrency patterns with these exercises progressing from basic to advanced.

ExerciseDifficultyTimeDescription
Goroutine CounterEasy10 minBuild a thread-safe counter using goroutines
Channel Ping-PongEasy10 minImplement bidirectional channel communication
Worker PoolMedium20 minCreate a pool of workers processing jobs
Rate LimiterMedium25 minBuild a token bucket rate limiter
Pipeline ProcessorHard30 minImplement a concurrent data processing pipeline
  • Goroutines: Lightweight concurrent execution
  • Channels: Safe communication between goroutines
  • Select: Multiplexing channel operations
  • Sync primitives: Mutex, WaitGroup, Once
  • Patterns: Worker pools, fan-out/fan-in, pipelines

Before starting these exercises, you should be comfortable with:

  • Basic Go syntax and types
  • Functions and methods
  • Chapter 4: Goroutines & Channels
  • Chapter 5: Sync Primitives
  1. Always use channels or sync primitives to protect shared state
  2. Consider using context.Context for cancellation in real-world code
  3. Use go run -race to detect race conditions