Yeah, you're really in trouble if a thread dies while holding a lock, because it's illegal (throws an exception) to call ReentrantLock#unlock if you're not the owning thread. So I'm not sure how you could possibly "clean up" in that case, but I don't see a way to do that automatically, either.
~~ Robert. That'd actually be a useful stunt for something I'm working on, too. On Sun, Jun 12, 2011 at 7:13 AM, Charles Oliver Nutter <head...@headius.com> wrote: > I'm trying to reimplement JRuby's version of Ruby's Mutex class, a > non-reentrant locking mechanism. One of the properties of a Mutex is > that when the thread holding its lock dies, the lock is released: > > ~/projects/jruby ➔ ruby -rthread -e "m = Mutex.new; Thread.new { > m.lock; p m.locked? }.join; p m.locked?" > true > false > > Previously our implementation simply maintained a volatile reference > to the thread owning the lock, considering it unlocked if the thread > was no longer alive. However that implementation did not use any > JVM-level monitor state, so it was not possible for Hotspot to detect > deadlocks between two threads trying to mutually acquire the same > locks in different order. A modified version that uses ReentrantLock > does show up in Hotspot's deadlock detection, but does not appear to > release locks on thread death: > > ~/projects/jruby ➔ jruby -rthread -e "m = Mutex.new; Thread.new { > m.lock; p m.locked? }.join; p m.locked?" > true > true > > Am I forced to use my own locking mechanism to get on-death lock > releasing, or is there some mechanism in java.util.* I've overlooked? > > - Charlie > > -- > You received this message because you are subscribed to the Google Groups > "JVM Languages" group. > To post to this group, send email to jvm-languages@googlegroups.com. > To unsubscribe from this group, send email to > jvm-languages+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/jvm-languages?hl=en. > > -- You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to jvm-languages@googlegroups.com. To unsubscribe from this group, send email to jvm-languages+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.