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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to