I am reading the book Go in action
.
This is how the unbuffered channel
are described:
An unbuffered channel is a channel with no capacity to hold any value before it’s received. These types of channels require both a sending and receiving goroutine to be ready at the same instant before any send or receive operation can complete. If the two goroutines aren’t ready at the same instant, the channel makes the goroutine that performs its respective send or receive operation first wait. Synchronization is inherent in the interaction between the send and receive on the channel. One can’t happenwithout the other.
The book use the following figure to illustrate the unbuffered channel
:
So I just wonder how about if there are three or more goroutine
which share the same channel
?
For example, three goroutine GA
GB
GC
share the same channel c
Now once GA
send message through c
, how do we make sure that both GB
and GC
will receive the message? Since as the book said:
These types of channels require both a sending and receiving goroutine to be ready at the same instant
Which means when two goroutine are exchanging the message, the third must lost the message.
Is this the right way goroutine run?