[concurrency-interest] Re: Improving RWLock compatibility - ownership test

Dawid Kurzyniec dawidk@mathcs.emory.edu
Mon, 29 Nov 2004 15:13:13 -0500

Larry Riedel wrote:

>>release() method of RWLocks doesn't check whether caller thread
>>owns the lock.  The lock is always released, even when it was
>>acquired by other thread. [...] I suggest to parameterize this
>>behavior by adding an optional parameter to RWLock constructor.
>I would like that, and/or a different class, and/or different
>(public) methods (one which checks and one which does not).
>In any case I think it should not be an implementation detail.
>If there will be no choice, I prefer the method does verify
>the owner, presuming that can be done extremely quickly.
I once asked about things along these lines; Doug Lea responded that 
historically, locks in dl.u.c. did not perform such checks, but the 
expert group decided that the locks in 1.5 should do that (it is a 
rather cheap operation), and they do. This new behavior is not being 
back-ported to dl.u.c. due to 1) fear of breaking compatibility with 
custom subclasses of these locks that people may have written, and 2) 
nothing really is being backported to dl.u.c. to encourage use of Java 1.5.

If you want this functionality in 1.4, I suggest you may want to check 
out the following faithful backport of java.util.concurrent to Java 1.4, 
currently available at:

http://www.mathcs.emory.edu/dcl/util/util-concurrent.jar (binaries)
http://www.mathcs.emory.edu/dcl/util/util-concurrent-src.jar (source code)
http://www.mathcs.emory.edu/dcl/util/util-concurrent-doc.jar (javadoc)

The proper Web page for this backport is in preparation. Some more 
details can be found in my earlier posting to the list, dated on 9/17/2004.