Commit aa763774 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: start goroutine ids at 1

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews, khr
https://golang.org/cl/117810043
parent c12c5dba
......@@ -167,6 +167,14 @@ func TestGoNil(t *testing.T) {
}
}
func TestMainGoroutineId(t *testing.T) {
output := executeTest(t, mainGoroutineIdSource, nil)
want := "panic: test\n\ngoroutine 1 [running]:\n"
if !strings.HasPrefix(output, want) {
t.Fatalf("output does not start with %q:\n%s", want, output)
}
}
const crashSource = `
package main
......@@ -365,3 +373,10 @@ func main() {
select{}
}
`
const mainGoroutineIdSource = `
package main
func main() {
panic("test")
}
`
......@@ -1882,7 +1882,11 @@ runtime·newproc1(FuncVal *fn, byte *argp, int32 narg, int32 nret, void *callerp
newg->gopc = (uintptr)callerpc;
newg->status = Grunnable;
if(p->goidcache == p->goidcacheend) {
// Sched.goidgen is the last allocated id,
// this batch must be [sched.goidgen+1, sched.goidgen+GoidCacheBatch].
// At startup sched.goidgen=0, so main goroutine receives goid=1.
p->goidcache = runtime·xadd64(&runtime·sched.goidgen, GoidCacheBatch);
p->goidcache -= GoidCacheBatch - 1;
p->goidcacheend = p->goidcache + GoidCacheBatch;
}
newg->goid = p->goidcache++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment