[concurrency-interest] tryAcquire vs tryAcquireShared in ReentrantReadWriteLock

Martin Buchholz martinrb at google.com
Tue Mar 16 18:30:39 EDT 2010

If a cas fails in tryAcquire, you know someone else
has just acquired a lock in a way that prevents you from
also acquiring it.

In tryAcquireShared, it may be the thread winning the cas
also acquired in shared mode, and so it is worth retrying.


On Tue, Mar 16, 2010 at 14:07, Khilan Gudka <khilan at doc.ic.ac.uk> wrote:
> Dear all,
> Please excuse me if this question is trivial but I was just wondering why
> tryAcquireShared in ReentrantReadWriteLock uses a loop to deal with CAS
> misses whereas tryAcquire just returns false. Is this because it's most
> likely that the lock is now unavailable and would therefore save a loop
> iteration?
> Khilan
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list