Why do I not get a deadlock when trying to read from a channel that never receives data in a goroutine but do in the main func


Why do I get a deadlock here

c := make(chan bool)

and not here

c := make(chan bool)
go func() {

I was expecting a deadlock in both cases because both are trying to read from a channel that is never going to receive data.


The child goroutine is blocked, but the current goroutine can proceed with its execution.

You get a deadlock only when all goroutines are blocked at the same time.

Answered By – LeGEC

Answer Checked By – David Marino (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.