package edu.rice.hj.example.comp322; import edu.rice.hj.api.HjPhaser; import edu.rice.hj.api.HjPhaserMode; import edu.rice.hj.api.HjSuspendable; import edu.rice.hj.api.SuspendableException; import static edu.rice.hj.Module1.*; /** * When a task T performs a signal operation, it notifies all the phasers it is registered on that it has completed all * the work expected by other tasks in the current phase ("shared" work). *

* Since signal is a non-blocking operation, an early execution of signal cannot create a deadlock. Later, when T * performs a next operation, the next degenerates to a wait since a signal has already been performed in the current * phase. *

* The execution of "local work" between signal and next is performed during phase transition. Referred to as a * "split-phase barrier" or "fuzzy barrier". * * @author Shams Imam (shams@rice.edu) */ public class SplitPhaseBarrierExample { public static void main(final String[] args) { launchHabaneroApp(new HjSuspendable() { @Override public void run() throws SuspendableException { finish(new HjSuspendable() { @Override public void run() throws SuspendableException { final HjPhaser ph = newPhaser(HjPhaserMode.SIG_WAIT); asyncPhased(ph.inMode(HjPhaserMode.SIG_WAIT), new HjSuspendable() { @Override public void run() throws SuspendableException { for (int p = 0; p < 4; p++) { System.out.println("Task-0: Shared work in phase-" + p); signal(); System.out.println("Task-0: Local work in phase-" + p); next(); System.out.println("Task-0: after barrier phase-" + p); } } }); asyncPhased(ph.inMode(HjPhaserMode.SIG_WAIT), new HjSuspendable() { @Override public void run() throws SuspendableException { for (int p = 0; p < 4; p++) { System.out.println("Task-1 Shared work in phase-" + p); signal(); System.out.println("Task-1 Local work in phase-" + p); next(); System.out.println("Task-1 after barrier phase-" + p); } } }); } }); } }); } }