Class ExactReentrantSharedUseExclusiveUseLock

java.lang.Object
com.mchange.v2.lock.ExactReentrantSharedUseExclusiveUseLock
All Implemented Interfaces:
SharedUseExclusiveUseLock

public class ExactReentrantSharedUseExclusiveUseLock extends Object implements SharedUseExclusiveUseLock

Fully reentrant. We could still separate the shared and exclusive wait() sets for greater efficiency under circumstances of high contention, but it would require extra synchronizations even under low contention, so we'll leave this as is, and maybe write a different class that presumes large wait sets.

Because this class is reentrant, lock relinquishes can't be idempotent -- we have to keep track of precisely how many times the lock was acquired and then release. Clients therefore have to be very careful that every acquisition is matched by exactly one relinquish. The way to do this is to acquire locks immediately before a try lock, and putting the relinquish in the finally block. One should not attempt to acquire the locks within the try block, because if the lock acquisition is interrupted, the lock relinquish in the finally block will run without the lock acquisition having succeeded.