[concurrency-interest] AQS Question (WAS: Need a special lock implementation)

Oliver Zeigermann oliver at zeigermann.de
Thu Aug 16 19:25:35 EDT 2007

I have finally come up with a solution based on AQS:

However, I had more state than would fit into an integer, so I
introduced more state (in form of a Set of reader threads).

Now my question: What is the right way to handle this mixed state? I
WRITE_LOCK into the state and added more details in form of the set of
reader threads for states A_SINGLE_READ_LOCK and MORE_READ_LOCKS. Does
that make sense? It looks really strange.

In case anyone minds, here is the code. Look for the inner class "Sync".


Thanks for any hints in advance and cheers


2007/8/15, Oliver Zeigermann <oliver at zeigermann.de>:
> Hi folks!
> I need a lock implementation having the following features:
> (1) read/write lock
> (2) ownership must be transferable from one thread to another
> (3) upgrade from read-lock to write-lock must be supported (I know
> this is deadlock prone)
> (4) one must be able to find out which thread holds which locks
> The lock is intended to protect resources that exist in large numer.
> Does anyone know of an implementation that has those features or at
> least something I could use as a starting point? Should I use AQS and
> start from scratch?
> Thanks in advance and cheers
> Oliver

More information about the Concurrency-interest mailing list