Goroutines and Channels
CONCEPTS:Go Goroutines and Channels
Question Variations
- "What is the difference between a goroutine and an operating-system thread?"
- "When does a channel send block?"
- "Who should close a channel?"
- "How do you prevent a goroutine leak?"
Why This Is Asked
Go concurrency is a core part of the language’s design. Interviewers use this question to assess whether you can coordinate concurrent work safely, explain channel blocking behavior, and avoid goroutine leaks.
Key Concepts
- A
gostatement starts a function call in a new goroutine. - Unbuffered channel sends and receives synchronize; buffered channels allow limited decoupling.
- Closing a channel signals that no more values will be sent.
- Context cancellation and bounded concurrency are essential for long-running services.
Question Variations
- “What is the difference between a goroutine and an operating-system thread?”
- “When does a channel send block?”
- “Who should close a channel?”
- “How do you prevent a goroutine leak?”