61 Star 343 Fork 417

infraboard / go-course

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
start.go 638 Bytes
一键复制 编辑 原始数据 按行查看 历史
Mr.Yu 提交于 2021-08-08 18:53 . 更新课件
package chnanel
import (
"fmt"
)
func A(send chan struct{}, recv chan struct{}) {
defer wg.Done()
msg := []string{"1", "2", "3"}
count := 0
for range recv {
if count > 2 {
return
}
fmt.Println(msg[count])
count++
send <- struct{}{}
}
}
func B(send chan struct{}, recv chan struct{}) {
defer wg.Done()
msg := []string{"A", "B", "C"}
count := 0
for range recv {
if count > 2 {
return
}
fmt.Println(msg[count])
count++
send <- struct{}{}
}
}
func SyncAB() {
a, b := make(chan struct{}), make(chan struct{})
wg.Add(2)
go A(a, b)
go B(b, a)
// 启动信号
b <- struct{}{}
wg.Wait()
}
Go
1
https://gitee.com/infraboard/go-course.git
git@gitee.com:infraboard/go-course.git
infraboard
go-course
go-course
19a3f401ff21

搜索帮助

53164aa7 5694891 3bd8fe86 5694891