class org.simgrid.msg.Semaphore

public class Semaphore

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.

Fields

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.

Constructors

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.

Methods

acquire

public native void acquire(double timeout)

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

finalize

protected void finalize()

Deletes this semaphore when the GC reclaims it

getCapacity

public int getCapacity()

Returns the semaphore capacity

nativeInit

public static native void nativeInit()

Class initializer, to initialize various JNI stuff

release

public native void release()

Releases the semaphore object

wouldBlock

public native 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.