Class Semaphore


  • public class Semaphore
    extends java.lang.Object
    A semaphore implemented on top of SimGrid synchronization mechanisms. You can use it exactly the same way that you use classical semaphores but to handle the interactions between the processes within the simulation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int capacity
      Semaphore capacity, defined when the semaphore is created.
    • Constructor Summary

      Constructors 
      Constructor Description
      Semaphore​(int capacity)
      Creates a new semaphore with the given capacity.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acquire()
      Locks on the semaphore object with no timeout
      void acquire​(double timeout)
      Locks on the semaphore object until the provided timeout expires
      protected void finalize()
      Deletes this semaphore when the GC reclaims it
      int getCapacity()
      Returns the semaphore capacity
      static void nativeInit()
      Class initializer, to initialize various JNI stuff
      void release()
      Releases the semaphore object
      boolean wouldBlock()
      returns a boolean indicating it this semaphore would block at this very specific time Note that the returned value may be wrong right after the function call, when you try to use it...
      • Methods inherited from class java.lang.Object

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

      • capacity

        protected final int capacity
        Semaphore capacity, defined when the semaphore is created. At most capacity process can acquire this semaphore at the same time.
    • Constructor Detail

      • Semaphore

        public Semaphore​(int capacity)
        Creates a new semaphore with the given capacity. At most capacity process can acquire this semaphore at the same time.
    • Method Detail

      • acquire

        public void acquire​(double timeout)
                     throws TimeoutException
        Locks on the semaphore object until the provided timeout expires
        Parameters:
        timeout - the duration of the lock
        Throws:
        TimeoutException - if the timeout expired before the semaphore could be acquired.
      • acquire

        public void acquire()
        Locks on the semaphore object with no timeout
      • release

        public void release()
        Releases the semaphore object
      • wouldBlock

        public boolean wouldBlock()
        returns a boolean indicating it this semaphore would block at this very specific time Note that the returned value may be wrong right after the function call, when you try to use it... But that's a classical semaphore issue, and SimGrid's semaphores are not different to usual ones here.
      • getCapacity

        public int getCapacity()
        Returns the semaphore capacity
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Deletes this semaphore when the GC reclaims it
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • nativeInit

        public static void nativeInit()
        Class initializer, to initialize various JNI stuff