50个阻塞的协程,不会有50个线程产生

package main
import (

_"os"
"fmt"
"time"

)

func main() {

for i:=0; i<50; i++ {
    c := make(chan int)
    go func( index int, cp chan int ) {//
        //for {
            fmt.Println("before send to chan, index is  ", index)
            cp<-0 // will block
            fmt.Println("after send, index is ", index)
        //}
    }(i,c)//

    go func(cp chan int ){
        time.Sleep(5*time.Second)
        <-cp
    }(c)
}
time.Sleep(10*time.Second)
//select{}

}

你可能感兴趣的:(Go,golang)