This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]: natThread.cc: Destroy join sync objects in finalizer


Tom Tromey wrote:

Hans> In this case, is it possible to invoke the cleanup code from
Hans> a java.lang.Thread finalizer?  Is java.lang.Thread allowed to have
Hans> a finalizer?

It can have a finalizer, but user code can override it.  So, there's
no guarantee it will be run.

A PhantomReference seems to be the most reliable way to do cleanup in
this situation. We could point it at the Thread object, then do
cleanup from a watching ReferenceQueue. This way the cleanup code
will only be called once the Thread (and its native data) are
irrevocably dead.


We could also just clean up the native state when the thread dies.
That is probably even better.


Yes, this would be cleaner, but we'd need to be careful that Thread.join() etc don't try to access the native state after it has been freed. To avoid race problems here we could perhaps register the finializer on the native state (natThread) itself rather than the java.lang.Thread, and atomically release it (set "thread->nt" to null) when the thread dies.

Bryce


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]