logo       

Re: more lock modes based on AbstractQueuedSynchronizer: msg#00004

java.jsr.166-concurrency

Subject: Re: more lock modes based on AbstractQueuedSynchronizer

Hu, Jinsong wrote:
I am new to jdk1.5 concurrent API, at the first glance of AbstractQueuedSynchronizer, it appears to me that this class has built-in support for Exclusive and Shared mode locks, if I want to support more type of locks, such as, IX, SIX, Update locks, which are common to database systems, can I still base on this framework, or I have to implement something similar from scratch?

and Matthias Ernst wrote:
* the lock state must be encodable in an int
* a lock request must be encodable in an int ...

So it seems well possible to do what you're thinking about.


Here, for example, is an implementation of a four-mode (read, write,
intent-read, and intent-write) lock.

https://dev.priorartisans.com/repos/jcip/trunk/src/main/jcip/rrlock/MMLock.java

I haven't done significant testing of this, so there are undoubtedly
bugs, but this should give you an idea of what is possible and how to
approach it.

You can also use this as a three-mode (read, write, and increment) lock.
The incrementLock() method is an alias for intentWriteLock().

I wrote this as part of a quad-tree implementation to demonstrate
intent locking. I'll post a link to it when it exists.

--tim


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise