Interface MultiLock
-
- All Known Implementing Classes:
PreciseMultiLock
public interface MultiLockProvides nonreenterant locking capability for a given ID. This class behaves similar to having an array of locks and locking/unlocking array elements but is light-weight. WARNING: These locks are not reenterant. If a thread locks the same ID multiple times it will wait forever.- Author:
- Evren Sirin
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidlock(int lockID)Locks the given ID, waiting indefinitely if another thread already has a lock.booleantryLock(int lockID)Tries to lock the given ID if it is possible to do so immediately and returntrue.voidunlock(int lockID)Unlocks the given ID.
-
-
-
Method Detail
-
lock
void lock(int lockID)
Locks the given ID, waiting indefinitely if another thread already has a lock.
-
tryLock
boolean tryLock(int lockID)
Tries to lock the given ID if it is possible to do so immediately and returntrue. If the lock is already held by another thread, this function immediately returnsfalse. Since this class does not provide reentarant behavior, this function will returnfalseeven if it is the same thread that holds the lock before this function call.
-
unlock
void unlock(int lockID) throws java.lang.IllegalArgumentExceptionUnlocks the given ID. There is no requirement that a thread that unlocks an ID must have locked that ID by callinglock(int).- Throws:
java.lang.IllegalArgumentException
-
-