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


Mohan Embar wrote:

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.



Believe it or not, my initial iteration attempted to clean up the native state when the thread died, but:

- I didn't know what to synchronize on.
- I figured it would require synchronizing on something every time we
needed to access the native state, which would unnecessary penalize
everyone because of the fringe case of troublemakers trying to
resurrect a thread.



Right, with my scheme above, no extra synchronization would be needed. It would still be safe to synchronize on the native state (join_mutex, etc), if thread->nt is non-null. The native state would not be destroyed until its finializer is run, so if a thread sees it as non-null, there is no danger of a race.


And, by registering the finalizier on the native state rather than the Thread object, we avoid conflicts with user finalizers.

Bryce


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