Package jromp.parallel
Class Barrier
java.lang.Object
jromp.parallel.Barrier
A barrier is a synchronization construct that allows multiple threads to wait
for each other at a common point.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
await()
Causes the current thread to wait until all threads have reached the barrier.int
getCount()
Returns the number of threads that must reach the barrier before they can continue.int
Returns the number of threads that have reached the barrier.getName()
Returns the name of the barrier.boolean
Returns a flag to indicate whether the threads are waiting at the barrier.void
reset()
Resets the barrier.toString()
-
Constructor Details
-
Barrier
Constructs a barrier with the specified name and count.- Parameters:
name
- the name of the barrier.count
- the number of threads that must reach the barrier before they can continue.
-
-
Method Details
-
getName
Returns the name of the barrier.- Returns:
- the name of the barrier.
-
getCount
public int getCount()Returns the number of threads that must reach the barrier before they can continue.- Returns:
- the number of threads that must reach the barrier before they can continue.
-
getCurrentCount
public int getCurrentCount()Returns the number of threads that have reached the barrier.- Returns:
- the number of threads that have reached the barrier.
-
isWaiting
public boolean isWaiting()Returns a flag to indicate whether the threads are waiting at the barrier.- Returns:
- a flag to indicate whether the threads are waiting at the barrier.
-
reset
public void reset()Resets the barrier. This method is called after all threads have reached the barrier. It resets the current count and the waiting flag. -
await
public void await()Causes the current thread to wait until all threads have reached the barrier. -
toString
-