Go语言 线程简单读写

来源:互联网 发布:快手网络直播怎么赚钱 编辑:程序博客网 时间:2024/05/19 16:36

一个线程负责读取

主线程负责写入


// test02 project main.gopackage mainimport ("fmt""time")/*一个线程负责读取主程序负责写入*///负责读取ifunc Process(ch chan int) {for {i := <-chfmt.Println("Process:", i)}}func main() {fmt.Println("Hello World!")ch := make(chan int, 1)go Process(ch)count := 1for {select {case ch <- count:count = count + 1default:time.Sleep(1e9)}}}


原创粉丝点击