There may not be any guarantee that the channel will always be full, but in 
practice your code always produces 100 results for me. Both in the 
playground <https://play.golang.org/p/zLozqzTtASh>, and on my machine  (go 
version go1.10 windows/amd64). With or without the Sleep commented out. Am 
I missing something?

- Jake

On Saturday, March 24, 2018 at 6:41:19 AM UTC-4, T L wrote:
>
> In the following example, there are 99 goroutines queuing and blocking on 
> sending a value to c.
> When the only buffered value is received, it looks there is a time 
> interval until the buffer is filled.
> Shouldn't it be that the receive from the only buffer and fill next 
> queuing value to the only buffer in one atomic operation?
>
>
> package main
>
> import "time"
>
> func main() {
>     c := make(chan int, 1)
>     for i := 0; i < 100; i++ {
>         go func() {
>             c <- 1
>         }()
>     }
>     
>     time.Sleep(time.Second)
>     
>     n := 0
>     for len(c) == cap(c) {
>         <-c
>         println(n, len(c)) // here, len(c) is always 0
>         n++
>         // time.Sleep(time.Second/1000) // if this line is not commented 
> off, there will be 100 lines output.
>     }
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to