| A latch is a boolean condition that is set at most once, ever.
Once a single release is issued, all acquires will pass.
Sample usage. Here are a set of classes that use
a latch as a start signal for a group of worker threads that
are created and started beforehand, and then later enabled.
class Worker implements Runnable {
private final Latch startSignal;
Worker(Latch l) { startSignal = l; }
public void run() {
startSignal.acquire();
doWork();
}
void doWork() { ... }
}
class Driver { // ...
void main() {
Latch go = new Latch();
for (int i = 0; i < N; ++i) // make threads
new Thread(new Worker(go)).start();
doSomethingElse(); // don't let run yet
go.release(); // let all threads proceed
}
}
[ Introduction to this package. ]
|