1 class org.simgrid.msg.Semaphore
2 ===============================
4 .. java:package:: org.simgrid.msg
7 .. java:type:: public class Semaphore
9 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.
16 .. java:field:: protected final int capacity
19 Semaphore capacity, defined when the semaphore is created. At most capacity process can acquire this semaphore at the same time.
26 .. java:constructor:: public Semaphore(int capacity)
29 Creates a new semaphore with the given capacity. At most capacity process can acquire this semaphore at the same time.
36 .. java:method:: public native void acquire(double timeout) throws TimeoutException
39 Locks on the semaphore object until the provided timeout expires
41 :param timeout: the duration of the lock
42 :throws TimeoutException: if the timeout expired before the semaphore could be acquired.
47 .. java:method:: public void acquire()
50 Locks on the semaphore object with no timeout
55 .. java:method:: @Deprecated @Override protected void finalize() throws Throwable
58 Deletes this semaphore when the GC reclaims it
63 .. java:method:: public int getCapacity()
66 Returns the semaphore capacity
71 .. java:method:: public static native void nativeInit()
74 Class initializer, to initialize various JNI stuff
79 .. java:method:: public native void release()
82 Releases the semaphore object
87 .. java:method:: public native boolean wouldBlock()
90 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.