[concurrency-interest] Upgrading a RL to WL in ReentrantReadWriteLock

Bela Ban belaban at yahoo.com
Tue Dec 5 11:26:19 EST 2006

Apologies if this has been asked before - I tried to google and search 
the concurrency-interest mailing list archives, to no avail (note that 
the archives at 
http://altair.cs.oswego.edu/mailman/private/concurrency-interest/ cannot 
be searched ! It would be good if you guys could change this...).

We're using our own reentrant lock classes in JBossCache 
(http://labs.jboss.com/portal/jbosscache/), but we'd like to replace 
them with the java.util.concurrent.* equivalent classes. However, for 
ReentrantReadWriteLock, we need upgrading capabilities from RLs tro WLs. 
>From the documentation of RRWL:

   * *Lock downgrading*

     Reentrancy also allows downgrading from the write lock to a read
     lock, by acquiring the write lock, then the read lock and then
     releasing the write lock. However, upgrading from a read lock to
     the write lock is *not* possible.

What was the rationale for this ?

We would prefer *not* to release the RL first, then acquire the WL, as 
other threads might then be able to acquire RLs or WLs after the 
original thread releases the RL but before it acquires the WL.

Bela Ban
Lead JGroups / JBoss Clustering team
JBoss - a division of Red Hat

More information about the Concurrency-interest mailing list