go基础知识-协程

1.进程,线程,协程(groutine)

2.协程是用户态线程(非内核线程),不需要操作系统进行抢占式调度

3. 关键字: go

4.理解MPG模型: M内核线程,P用户级线程,G协程;

 

案例:

var (
syncGp sync.WaitGroup
)

func main(){
syncGp.Add(1)
go func() {
fmt.Println("go grouthine process")
syncGp.Done()
}()
syncGp.Wait()
fmt.Println("main process")
}
posted @ 2022-03-04 18:06  说好的你  阅读(51)  评论(0)    收藏  举报