Package org.simgrid.msg
Class Semaphore
- java.lang.Object
-
- org.simgrid.msg.Semaphore
-
public class Semaphore extends java.lang.ObjectA 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 intcapacitySemaphore 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 voidacquire()Locks on the semaphore object with no timeoutvoidacquire(double timeout)Locks on the semaphore object until the provided timeout expiresprotected voidfinalize()Deletes this semaphore when the GC reclaims itintgetCapacity()Returns the semaphore capacitystatic voidnativeInit()Class initializer, to initialize various JNI stuffvoidrelease()Releases the semaphore objectbooleanwouldBlock()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 TimeoutExceptionLocks 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.ThrowableDeletes this semaphore when the GC reclaims it- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
nativeInit
public static void nativeInit()
Class initializer, to initialize various JNI stuff
-
-