Semaphore
Date: 2013-11-17

org.simgrid.msg

## Class Semaphore

- java.lang.Object
- - org.simgrid.msg.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 and Description
    --- | ---
    `protected int` | `capacity` Semaphore capacity, defined when the semaphore is created.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Semaphore(int capacity)` Creates a new semaphore with the given capacity.

  - ### Method Summary

    Methods
    Modifier and Type | Method and 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
    `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
      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()

      Deletes this semaphore
      Overrides:
        `finalize` in class `java.lang.Object`

    - #### nativeInit

          public static void nativeInit()

      Class initializer, to initialize various JNI stuff