Avoid deadlock creating new thread.
authorIan Lance Taylor <ian@gcc.gnu.org>
Sat, 22 Jan 2011 00:12:00 +0000 (00:12 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Sat, 22 Jan 2011 00:12:00 +0000 (00:12 +0000)
From-SVN: r169114

libgo/runtime/malloc.goc

index be37777d7bd983f4ae43836d8cf087aa6e04c221..d826d479f5c68da01cbe249031cbbd33ce440ca2 100644 (file)
@@ -255,6 +255,9 @@ runtime_allocmcache(void)
 {
        MCache *c;
 
+       if(!__sync_bool_compare_and_swap(&m->mallocing, 0, 1))
+               runtime_throw("allocmcache - deadlock");
+
        runtime_lock(&runtime_mheap);
        c = runtime_FixAlloc_Alloc(&runtime_mheap.cachealloc);
 
@@ -264,6 +267,11 @@ runtime_allocmcache(void)
        mstats.mcache_inuse = runtime_mheap.cachealloc.inuse;
        mstats.mcache_sys = runtime_mheap.cachealloc.sys;
        runtime_unlock(&runtime_mheap);
+
+       __sync_bool_compare_and_swap(&m->mallocing, 1, 0);
+       if(__sync_bool_compare_and_swap(&m->gcing, 1, 0))
+               __go_run_goroutine_gc(2);
+
        return c;
 }