java.lang.Object
org.cybergarage.util.Mutex

public class Mutexextends Object
A simple mutex implementation for thread synchronization. This class provides basic locking mechanisms using synchronized methods and wait/notify for inter-thread communication.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    True while a thread holds the lock.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Mutex instance in the unlocked state.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    void
    Acquires the lock, blocking if necessary until the lock is available.
    void
    Releases the lock and notifies all waiting threads.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • syncLock

      private boolean syncLock
      True while a thread holds the lock.
  • Constructor Details

    • Mutex

      public Mutex()
      Creates a new Mutex instance in the unlocked state.
  • Method Details

    • lock

      public void lock()
      Acquires the lock, blocking if necessary until the lock is available. If the lock is already held, the calling thread will wait until it's released.
    • unlock

      public void unlock()
      Releases the lock and notifies all waiting threads. This method should only be called by the thread that currently holds the lock.