Skip to content

Instantly share code, notes, and snippets.

@xyun1996

xyun1996/proc.go Secret

Last active May 10, 2022
Embed
What would you like to do?
newproc
func newproc(siz int32, fn *funcval) {
argp := add(unsafe.Pointer(&fn), sys.PtrSize)
gp := getg()
pc := getcallerpc()
systemstack(func() {
newg := newproc1(fn, argp, siz, gp, pc)
_p_ := getg().m.p.ptr()
runqput(_p_, newg, true) //true 始终把p的runnext设置为newg
if mainStarted {
wakep()
}
})
}
func runqput(_p_ *p, gp *g, next bool) {
if randomizeScheduler && next && fastrand()%2 == 0 {
next = false
}
if next {
retryNext:
oldnext := _p_.runnext
if !_p_.runnext.cas(oldnext, guintptr(unsafe.Pointer(gp))) {
goto retryNext
}
if oldnext == 0 {
return
}
// Kick the old runnext out to the regular run queue.
gp = oldnext.ptr()
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment