# HG changeset patch # User Michael Beyl # Date 1161705138 -7200 # Node ID 7bfdc51fcb65d4488e9e3d9659d2807d138b6ac6 # Parent 5e82e27705ccb6c3874520997574cf0f4b440eec Avoid deadlock when free is called by finalization code (Stefan Vogel) diff -r 5e82e27705cc -r 7bfdc51fcb65 ExternalBytes.st --- a/ExternalBytes.st Tue Oct 24 12:40:39 2006 +0200 +++ b/ExternalBytes.st Tue Oct 24 17:52:18 2006 +0200 @@ -9,12 +9,11 @@ other person. No title to or ownership of the software is hereby transferred. " - "{ Package: 'stx:libbasic' }" UninterpretedBytes subclass:#ExternalBytes instanceVariableNames:'address* size' - classVariableNames:'AllocatedInstances Lobby DebugMalloc TraceMalloc AccessLock' + classVariableNames:'AllocatedInstances Lobby DebugMalloc TraceMalloc' poolDictionaries:'' category:'System-Support' ! @@ -1196,12 +1195,20 @@ class variable - this prevents it from ever being finalized by the garbage collector, thus protecting the underlying memory." - AccessLock critical:[ - AllocatedInstances isNil ifTrue:[ - AllocatedInstances := IdentitySet new - ]. - AllocatedInstances add:self - ] + |wasBlocked| + + + "using a Semaphore can cause a deadlock, since unprotectFromGC may be called by + a finalization method" + + wasBlocked := OperatingSystem blockInterrupts. +"/ AccessLock critical:[ + AllocatedInstances isNil ifTrue:[ + AllocatedInstances := IdentitySet new + ]. + AllocatedInstances add:self. +"/ ] + wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. ! unprotectFromGC @@ -1210,11 +1217,16 @@ the next garbage collect will finalize the receiver and the underlying memory be freed." - AllocatedInstances notNil ifTrue:[ - AccessLock critical:[ - AllocatedInstances remove:self ifAbsent:nil - ] - ] + |wasBlocked| + + "using a Semaphore can cause a deadlock, since protectFromGC may be interrupted by me + being called by a finalization method" + + wasBlocked := OperatingSystem blockInterrupts. +"/ AccessLock critical:[ + AllocatedInstances remove:self ifAbsent:nil. +"/ ] + wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. ! ! !ExternalBytes methodsFor:'resizing'! @@ -1263,7 +1275,7 @@ !ExternalBytes class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/ExternalBytes.st,v 1.64 2006-09-14 19:08:39 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/ExternalBytes.st,v 1.65 2006-10-24 15:52:18 mb Exp $' ! ! ExternalBytes initialize!