Lua SPOT
v1.0

nl.uva.np.luaspot
Class Semaphore

java.lang.Object
  extended by nl.uva.np.luaspot.Semaphore

public class Semaphore
extends java.lang.Object

A simple semaphore object that can be used to guard a critical section from execution of multiple threads at the same time. Calling the get() method will activate the semaphore so all other threads that try to call the get() function will wait() until the thread that acquire the get() release the lock by calling release().

Keep in mind that a get() invocation should be paired with a release() call.


Constructor Summary
Semaphore()
           
 
Method Summary
 void get()
          Acquire the lock.
 void release()
          Release the acquired lock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Semaphore

public Semaphore()
Method Detail

get

public void get()
Acquire the lock. If the lock is already acquired by a thread, other threads will get blocked until that thread release the lock. In this case, the first thread can proceed to the critical section and run the code safely.


release

public void release()
Release the acquired lock. This should be called after executing a critical section.


Lua SPOT
v1.0