并发编程
goroutine
启动单个goroutine
package main
import "fmt"
func hello() {
fmt.Println("Hello Gorotine")
}
func main() {
go hello() // 启动一个goroutine,并发调用函数hello
fmt.Println("main done!")
time.Sleep(time.Second) // 防止hello协程还未执行,主线程就退出了
}main done!
Hello Gorotinesync.WaitGroup
channel
无缓冲channel(同步通道)
有缓冲channel
关闭channel
遍历channel
只写只读管道
错误处理
select关键字
解决管道阻塞
练习
练习1
练习2
最后更新于