Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: JRuby 1.7.0.RC1
-
Component/s: None
-
Labels:None
-
Environment:jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) Client VM 1.6.0_26) [Windows XP-x86-java]
-
Testcase included:yes
-
Number of attachments :
Description
Currently if you attempt to double lock a mutex, it responds with
"ThreadError: Mutex is not locked"
but in reality the problem is that the mutex is locked (I think this may be actually a secondary error, obscuring the real error, because it is also reporting the wrong line number, it appears, compared to MRI).
require 'thread'
a = Mutex.new
a.synchronize {
a.synchronize { # this line raises
}
}
Mutex#synchronize is unlocking the lock in the finally block, so that the Exception that the inner synchronize block throws is swallowed up, and the outer synchronize block tries to unlock the lock that the current thread doesn't have any longer.
I pushed a fix to the master branch (e6b9be7). Now the example above throws:
ThreadError: Mutex relocking by same thread lock at org/jruby/ext/thread/Mutex.java:91 synchronize at org/jruby/ext/thread/Mutex.java:164 __file__ at temp/jruby-6275.rb:5 synchronize at org/jruby/ext/thread/Mutex.java:165 (root) at temp/jruby-6275.rb:4The error messages are different in MRI 1.8.x and 1.9.3. Consequently, for now, I am not overly concerned with exactly matching the error message.
Regrettably, there is no RubySpec for Mutex at all.