Communication in Go via channels

Issue

Consider such situation. There are one main goroutine and ten subsidiary
goroutines. All of them have access to channel. Main one sends 1000 numbers to this channel and subsidiary ones will read from it.
Is there any guarantee that each subsidiary goroutine will read exactly 100 numbers or this amount may vary like some goroutine will read 99 numbers and another 101?

Solution

No, there is no guarantee, because it depends on the runtime of every goroutine and that depends on how well the goroutines are distributed across the CPU.

Answered By – user8981190

Answer Checked By – Katrina (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.