初始化Go学习项目
This commit is contained in:
23
go-atomic-cpu/cpu_channel_wait.go
Normal file
23
go-atomic-cpu/cpu_channel_wait.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
stop := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
select {
|
||||
case <-stop:
|
||||
fmt.Println("worker 收到停止信号,退出")
|
||||
}
|
||||
}()
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
fmt.Println("main: 关闭 stop channel")
|
||||
close(stop)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
Reference in New Issue
Block a user