aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/proc.c
diff options
context:
space:
mode:
authorDmitriy Vyukov <dvyukov@google.com>2014-07-16 12:19:33 +0400
committerDmitriy Vyukov <dvyukov@google.com>2014-07-16 12:19:33 +0400
commitaa76377423ac77d025284a6c11f0c874740202e8 (patch)
tree294a42ddf9b725b31212d3439dadfb0c428b8e2a /src/pkg/runtime/proc.c
parentc12c5dba9c9d81242569f4108b707c6c16dfa066 (diff)
downloadgo-aa76377423ac77d025284a6c11f0c874740202e8.tar.xz
runtime: start goroutine ids at 1
LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews, khr https://golang.org/cl/117810043
Diffstat (limited to 'src/pkg/runtime/proc.c')
-rw-r--r--src/pkg/runtime/proc.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c
index 22ddce5bd4..0b75415aca 100644
--- a/src/pkg/runtime/proc.c
+++ b/src/pkg/runtime/proc.c
@@ -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++;