Goroutines, channels, select, sync package, WaitGroup, context and common concurrency patterns in Go.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a goroutine?
Show answer
A lightweight thread of execution managed by the Go runtime, cheaper than OS threads
- What keyword launches a goroutine?
Show answer
go
- What happens to all goroutines when main() exits?
Show answer
They are terminated immediately, regardless of whether they finished
- How many goroutines can a Go program typically handle?
Show answer
Thousands to millions, depending on memory and system resources
- Goroutines are scheduled by which Go runtime component?
Show answer
The scheduler, which multiplexes goroutines onto OS threads
- What is a channel?
Show answer
A typed conduit for sending and receiving values between goroutines
- Syntax to create an unbuffered channel of int
Show answer
make(chan int)
- Syntax to create a buffered channel of string with capacity 5
Show answer
make(chan string, 5)
- Syntax to send value x to channel c
Show answer
c <- x
- Syntax to receive from channel c into variable v
Show answer
v := <-c
- How to check if a value received from channel c is from a closed channel?
Show answer
v, ok := <-c; ok is false if the channel is closed
- What happens when you send to a closed channel?
Show answer
panic
- What value is returned when receiving from a closed channel?
Show answer
The zero value of the channel type
- Syntax to close a channel c
Show answer
close(c)
- How to iterate over values sent to channel c until it closes?
Show answer
for v := range c { ... }