DEV Community

Divyanshu Shekhar
Divyanshu Shekhar

Posted on • Edited on

1 1

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs