How does a goroutine behave when it creates a channel

Suppose I have a function which creates a goroutine and inside that goroutine, I create a channel. My question is that when we create N go routines, N separate channels will be created?

1 answer

  • answered 2019-06-11 22:54 Dirbaio

    Yes, every time you create a channel with make, you get a new channel.

    If you want multiple goroutines to share a channel instead, you have to create the channel in the parent goroutine and pass it to the child goroutines.