DEV Community

Divyanshu Shekhar
Divyanshu Shekhar

Posted on • Updated on

Golang Channel Deadlock

#go

Golang Channel Deadlock

The number of channels is limited and whenever we try to receive or send value from and to the channel out of number, a deadlock occurs.

1. Receiving channels more than expected

    go func(ch <-chan int) {
        i := <-ch
        j := <-ch
        fmt.Println("Value of Channel i,j =", i, j)
        wg.Done()
    }(ch)

Error:- fatal error: all goroutines are asleep – deadlock!
Enter fullscreen mode Exit fullscreen mode

Here, there is only a single channel from where data is sent, and two receiving channels and thus Deadlock occurs.

Read Full Post on Golang Channel Deadlock.

Top comments (0)