type Ch struct {
closeChan chan byte // 关闭通知
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
go func() {
for {
fmt.Println("1111")
select {
case s:= <-ctx.Done():
fmt.Println("1111333",s)
}
}
}()
for j:=0;j<100;j++ {
go func(j int) {
for {
fmt.Println("2222")
select {
case <-ctx.Done():
fmt.Println("2222333",j)
}
}
}(j)
}
go func() {
for {
fmt.Println("444")
select {
case <-ctx.Done():
fmt.Println("444333")
}
}
}()
time.Sleep(1*time.Second)
for i:=0;i<10000;i++ {
go func() {
cancel()
}()
}
cancel()
for i:=0;i<10000;i++ {
go func() {
cancel()
}()
}
time.Sleep(10*time.Second)
}
go的cancel是高并发的