[concurrency-interest] ReentrantReadWriteLock should throw ex on writeLock().lock() if read lock held?

Giuliano Mega giuliano.mega at gmail.com
Tue Sep 5 09:57:25 EDT 2006


Hi Jed,

I always thought that Lock.tryLock was supposed to play this role
(except that it returns false instead of throwing an exception). Am I
missing something from your problem that prevents you from using
tryLock?

Best,

On 9/5/06, Jed Wesley-Smith <jed at atlassian.com> wrote:
> Just a quick question regarding the acquisition policy of the
> ReentrantReadWriteLock if a reader tries to grab the write lock. What
> currently happens is that the call to writeLock().lock() blocks forever.
> Wouldn't it be better to throw some sort of exception like
> IllegalMonitorStateException (not that one specifically, but something
> like it)?. That way you would fail-fast and find the problem fairly
> quickly...
>
> Or in other words, is there a specific reason you would want to call
> something in such a way that the only return possible is an
> InterruptedException if you are lucky enough that another thread notices
> your plight and interrupts you :-)
>
> --
> cheers,
> - jed.
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>


-- 
Giuliano Mega <giuliano at ime.usp.br>


More information about the Concurrency-interest mailing list