package pt.ul.jarmus.deadlocks.skip;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.Phaser;
import pt.ul.jarmus.JArmus;
public class FjPhaser {
public static void main(String[] args) throws InterruptedException {
final Phaser barrier = new Phaser(2);
final ForkJoinPool pool = new ForkJoinPool();
ForkJoinTask<?> t1 = pool.submit(ForkJoinTask.adapt(new Runnable() { // T1
@Override
public void run() {
JArmus.register(barrier); // Is using the latch
try {
ForkJoinTask.adapt(new Runnable() { // T2
@Override
public void run() {
JArmus.register(barrier); // Is using the latch
barrier.arriveAndAwaitAdvance(); // wait for T1
}
}).invoke(); // wait for T2
barrier.arriveAndAwaitAdvance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}));
t1.join();
}
}