Avoid deadlock creating new thread.

From-SVN: r169114
This commit is contained in:
Ian Lance Taylor 2011-01-22 00:12:00 +00:00
parent cf606aeb06
commit 7e33c4aadc
1 changed files with 8 additions and 0 deletions

View 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;
}