golang 无缓冲channel

时间:2024-01-11 16:05:50

golang 无缓冲channel

package main

import "fmt"

func main() {

    // 1S =1000ms
//1ms = 1000us
//1us =1000ns
/*
定义channel:make(chan 类型,容量)
ch :=make(chan string)
写端 ch <-"hello"
读端 str := <-ch */ ch :=make(chan string) //无缓冲channel
fmt.Println("len(ch)=",len(ch),"cap(ch)=",cap(ch)) go func() {
for i:=;i<;i++{
fmt.Println("i=",i)
}
ch <-"子go打印完毕"
}() str := <-ch
fmt.Println("str=",str) }