Interface MultiLock

  • All Known Implementing Classes:
    PreciseMultiLock

    public interface MultiLock
    Provides 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
      void lock​(int lockID)
      Locks the given ID, waiting indefinitely if another thread already has a lock.
      boolean tryLock​(int lockID)
      Tries to lock the given ID if it is possible to do so immediately and return true.
      void unlock​(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 return true. If the lock is already held by another thread, this function immediately returns false. Since this class does not provide reentarant behavior, this function will return false even if it is the same thread that holds the lock before this function call.
      • unlock

        void unlock​(int lockID)
             throws java.lang.IllegalArgumentException
        Unlocks the given ID. There is no requirement that a thread that unlocks an ID must have locked that ID by calling lock(int).
        Throws:
        java.lang.IllegalArgumentException