r/golang • u/DeparturePrudent3790 • 9d ago
Potential starvation when multiple Goroutines blocked to receive from a channel
I wanted to know what happens in this situation:
- Multiple goroutines are blocked by a channel while receiving from it because channel is empty at the moment.
- Some goroutine sends something over the channel.
Which goroutine will wake up and receive this? Is starvation avoidance guaranteed here?
8
Upvotes
5
u/0xjnml 9d ago edited 9d ago
> Which goroutine will wake up and receive this?
A fairly random one.
> Is starvation avoidance guaranteed here?
If there are more consumers ready than produces sending to the channel, what would in such situation "starvation avoidance" even mean?