newproc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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