mirror of
https://github.com/golang/go
synced 2024-11-23 18:20:04 -07:00
runtime: start goroutine ids at 1
LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews, khr https://golang.org/cl/117810043
This commit is contained in:
parent
c12c5dba9c
commit
aa76377423
@ -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++;
|
||||
|
Loading…
Reference in New Issue
Block a user