mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: preempt long-running goroutines
If a goroutine runs for more than 10ms, preempt it. Update #543. R=rsc CC=golang-dev https://golang.org/cl/10796043
This commit is contained in:
parent
58f12ffd79
commit
bc31bcccd3
3 changed files with 60 additions and 20 deletions
|
|
@ -244,11 +244,11 @@ runtime·newstack(void)
|
|||
if(gp->stackguard0 == (uintptr)StackPreempt) {
|
||||
if(gp == m->g0)
|
||||
runtime·throw("runtime: preempt g0");
|
||||
if(oldstatus == Grunning && (m->p == nil || m->p->status != Prunning))
|
||||
if(oldstatus == Grunning && m->p == nil)
|
||||
runtime·throw("runtime: g is running but p is not");
|
||||
// Be conservative about where we preempt.
|
||||
// We are interested in preempting user Go code, not runtime code.
|
||||
if(oldstatus != Grunning || m->locks || m->mallocing || m->gcing) {
|
||||
if(oldstatus != Grunning || m->locks || m->mallocing || m->gcing || m->p->status != Prunning) {
|
||||
// Let the goroutine keep running for now.
|
||||
// gp->preempt is set, so it will be preempted next time.
|
||||
gp->stackguard0 = gp->stackguard;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue