From 41296315f7b1e0eccfa6c94c49f1cdd977f741fb Mon Sep 17 00:00:00 2001 From: Takano Akio Date: Fri, 6 Sep 2013 19:55:37 +0900 Subject: [PATCH] Avoid allocating while holding a lock (#8242) This reverts commit 6770663f764db76dbb7138ccb3aea0527d194151. If the program enters the garbage collector with the closure lock held, it will confuse the garbage collector and will result in an infinite loop in evacuate(). Signed-off-by: Austin Seipp --- rts/PrimOps.cmm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm index 08e7af08a1..dbced84083 100644 --- a/rts/PrimOps.cmm +++ b/rts/PrimOps.cmm @@ -460,14 +460,6 @@ stg_addCFinalizzerToWeakzh ( W_ fptr, // finalizer { W_ c, info; - LOCK_CLOSURE(w, info); - - if (info == stg_DEAD_WEAK_info) { - // Already dead. - unlockClosure(w, info); - return (0); - } - ALLOC_PRIM (SIZEOF_StgCFinalizerList) c = Hp - SIZEOF_StgCFinalizerList + WDS(1); @@ -478,6 +470,14 @@ stg_addCFinalizzerToWeakzh ( W_ fptr, // finalizer StgCFinalizerList_eptr(c) = eptr; StgCFinalizerList_flag(c) = flag; + LOCK_CLOSURE(w, info); + + if (info == stg_DEAD_WEAK_info) { + // Already dead. + unlockClosure(w, info); + return (0); + } + StgCFinalizerList_link(c) = StgWeak_cfinalizers(w); StgWeak_cfinalizers(w) = c; -- GitLab