[commit: ghc] master: Avoid allocating while holding a lock (#8242) (4129631)

git at git.haskell.org git at git.haskell.org
Sun Sep 8 10:56:46 CEST 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/41296315f7b1e0eccfa6c94c49f1cdd977f741fb/ghc

>---------------------------------------------------------------

commit 41296315f7b1e0eccfa6c94c49f1cdd977f741fb
Author: Takano Akio <aljee at hyper.cx>
Date:   Fri Sep 6 19:55:37 2013 +0900

    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 <aseipp at pobox.com>


>---------------------------------------------------------------

41296315f7b1e0eccfa6c94c49f1cdd977f741fb
 rts/PrimOps.cmm |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
index 08e7af0..dbced84 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;
 





More information about the ghc-commits mailing list