RE: JavaMemoryModel: Another Java threading issue (finalization)

From: David Holmes (dholmes@dltech.com.au)
Date: Tue Apr 01 2003 - 13:54:36 EST


Jerry Schwarz wrote:
> The next sentence is that "optimizing transformations of a
> program can be designed that reduce the number of objects that are
> reachable to be less than those which would naively be considered
> reachable."

Sure. As discussed the end result is that there is always a race
between an unsynchronised finalizer (and similarly for "weak"
references) and normal use of the object. This means the finalizer can
execute before code that notionally/naively is expected to complete
first.

Should this race be removed?

Well I was just considering a use of a finalizer that involved freeing
a native memory block. It would be really bad if the finalizer could
run before the method that will use the native memory. ;-) It would
also be really ugly to have to use synchronization just in case the VM
uses a separate finalizer thread.

Hmmm. I suppose if we just said "an object is always reachable while
an invocation upon it is active" then the compiler folk would get
upset?

David Holmes

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:42 EDT