package edu.rice.hj.example.comp322; import edu.rice.hj.api.HjPhaser; import edu.rice.hj.api.HjPhaserMode; 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(() -> { finish(() -> { final HjPhaser ph = newPhaser(HjPhaserMode.SIG_WAIT); asyncPhased(ph.inMode(HjPhaserMode.SIG_WAIT), () -> { 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), () -> { 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); } }); }); }); } }