Package 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 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 timeoutvoid
acquire(double timeout)
Locks on the semaphore object until the provided timeout expiresprotected void
finalize()
Deletes this semaphore when the GC reclaims itint
getCapacity()
Returns the semaphore capacitystatic void
nativeInit()
Class initializer, to initialize various JNI stuffvoid
release()
Releases the semaphore objectboolean
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...
-
-
-
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 classjava.lang.Object
- Throws:
java.lang.Throwable
-
nativeInit
public static void nativeInit()
Class initializer, to initialize various JNI stuff
-
-