Class Semaphore


  • public class Semaphore
    extends java.lang.Object
    Counting Semaphore.
    • Constructor Summary

      Constructors 
      Constructor Description
      Semaphore()
      Semaphore constructor.
      Semaphore​(int n)
      Semaphore constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void await()
      The Dijkstra P operation: delays until the internal counter is greater than 0 and then decrements it.
      static void setMeanSleepAfterAwait​(int ms)
      If the parameter is greater than 0 more arbitrary interleavings will be introduced.
      void signal()
      The Dijkstra V operation: increments the internal counter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Semaphore

        public Semaphore()
        Semaphore constructor. Internal counter initizalised to 0.
      • Semaphore

        public Semaphore​(int n)
        Semaphore constructor. Internal counter initizalised to n if n is positive, 0 otherwise.
    • Method Detail

      • setMeanSleepAfterAwait

        public static void setMeanSleepAfterAwait​(int ms)
        If the parameter is greater than 0 more arbitrary interleavings will be introduced.
      • await

        public void await()
        The Dijkstra P operation: delays until the internal counter is greater than 0 and then decrements it. The usual name of this method is wait but, unfortunately, wait is an important predefined method in Object and we don't want to invalidate its semantics.
      • signal

        public void signal()
        The Dijkstra V operation: increments the internal counter.