1、GPM简介
- G:Groutine,协程
- M:Machine,内核线程,对应CPU
- P:Processor,G和M的调度对象,包含LRQ
type g struct {
....
m *m
sched gobuf
goid int64
....
}
type gobuf struct {
sp uintptr
pc uintptr
....
}
注意,LRQ(P的Local Runable Queue),GRQ(Global Runable Queue,当Local Queue满了之后才会写入GRQ)
2、Goroutine状态
注意,goroutine状态转换时两个重要方法,gopark()、goready()