]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix potential GC deadlock
authorDmitriy Vyukov <dvyukov@google.com>
Mon, 25 Jun 2012 07:08:09 +0000 (11:08 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Mon, 25 Jun 2012 07:08:09 +0000 (11:08 +0400)
The issue seems to not be triggered right now,
but I've seen the deadlock after some other legal
modifications to runtime.
So I think we are safer this way.

R=rsc, r
CC=golang-dev
https://golang.org/cl/6339051

src/pkg/runtime/mgc0.c

index 5f1bff2c461d7dfb230222a98b30abb5e3b42386..70d0a0f2e2843cf7b66031dd5e887132ff46a30f 100644 (file)
@@ -905,12 +905,14 @@ runtime·gc(int32 force)
        work.debugmarkdone = 0;
        work.nproc = runtime·gcprocs();
        addroots();
+       m->locks++;     // disable gc during mallocs in parforalloc
        if(work.markfor == nil)
                work.markfor = runtime·parforalloc(MaxGcproc);
        runtime·parforsetup(work.markfor, work.nproc, work.nroot, nil, false, markroot);
        if(work.sweepfor == nil)
                work.sweepfor = runtime·parforalloc(MaxGcproc);
        runtime·parforsetup(work.sweepfor, work.nproc, runtime·mheap.nspan, nil, true, sweepspan);
+       m->locks--;
        if(work.nproc > 1) {
                runtime·noteclear(&work.alldone);
                runtime·helpgc(work.nproc);