Examples of Phaser


Examples of java.util.concurrent.Phaser

   */
  @Test
  public void falseDeadlock1c() throws InterruptedException, InstantiationException, IllegalAccessException {
    initAvoidance();
       
    final Phaser a = new Phaser(1);
    final Phaser b = new Phaser(1);
    JArmus.register(a);
    JArmus.register(b);

    PhaserChecker ph = new PhaserChecker();
    ph.onArrive(b);
View Full Code Here

Examples of java.util.concurrent.Phaser

  public void falseDeadlock1d() throws InterruptedException, InstantiationException, IllegalAccessException {
    PhaserListener facade = Mockito.mock(PhaserListener.class);
    PhaserObserver.aspectOf().setListener(facade);
    initAvoidance();
   
    final Phaser a = new Phaser(1);
    final Phaser b = new Phaser(1);
    JArmus.register(a);
    JArmus.register(b);
    b.arrive();
    a.arriveAndAwaitAdvance();
    b.awaitAdvance(0);
   
   
    // Verify phase
    InOrder inOrder = inOrder(facade);
    inOrder.verify(facade).onArrive(b);
View Full Code Here

Examples of java.util.concurrent.Phaser

   */
  @Test
  public void forgotToSetBlocked() throws InstantiationException, IllegalAccessException {
    initAvoidance();
   
    final Phaser barrier1 = new Phaser(1);
    JArmus.register(barrier1);
    assertTrue(JArmus.getSetup().getController().isRegistered(barrier1));
    try {
      barrier1.awaitAdvance(0);
    } catch (DeadlockIdentifiedException e) {
      // ok
    }
  }
View Full Code Here

Examples of java.util.concurrent.Phaser

  }
 
  @Parameters
  public static Collection<Object[]> data() {
    List<Object[]> result = new ArrayList<>();
    result.add(new Object[]{new Phaser(1)});
    result.add(new Object[]{new pt.ul.jarmus.ext.Phaser(1)});
    return result;
  }
View Full Code Here

Examples of java.util.concurrent.Phaser

public class SplitPhase {
  protected static final boolean condition = false;

  public static void main(String[] args) throws InterruptedException {
    final Phaser a = new Phaser(2);
    final Phaser b = new Phaser(2);
    new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          JArmus.register(a);
          JArmus.register(b);
          if (condition) {
            b.arrive();
          }
          a.arriveAndAwaitAdvance();
          if (condition) {
            b.awaitAdvance(0);
          } else {
            b.arriveAndAwaitAdvance();
          }
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }).start();
    JArmus.register(a);
    JArmus.register(b);
    b.arriveAndAwaitAdvance();
    a.arriveAndAwaitAdvance();
  }
View Full Code Here

Examples of java.util.concurrent.Phaser

public class ProducerConsumer3 {
  protected static final int nz = 1000;

  public static void main(String[] args) {
    final int num_threads = 3;
    final Phaser ph[] = new Phaser[num_threads];
    for (int i = 0; i < num_threads; i++) {
      ph[i] = new Phaser(2);
    }
    for (int i = 0; i < num_threads; i++) {
      final Phaser curr = ph[i];
      final Phaser neighbour = ph[(i - 1 + num_threads) % num_threads];
      @SuppressWarnings("unused")
      final int id = i;
      new Thread(new Runnable() {
        @Override
        public void run() {
          JArmus.register(curr);
          JArmus.register(neighbour);
          for (int k = 1; k <= nz - 2; k++) {
            step(k);
            /* we introduce the deadlock by commenting one of the
               boundary conditions */
            //if (id > 0) {
              neighbour.arriveAndAwaitAdvance();
            //}
            step2(k);
            //if (id < num_threads - 1) {
              curr.arriveAndAwaitAdvance();
            //}
View Full Code Here

Examples of java.util.concurrent.Phaser

public class ProducerConsumer {
  protected static final int nz = 1000;

  public static void main(String[] args) {
    final int num_threads = 3;
    final Phaser ph[] = new Phaser[num_threads];
    for (int i = 0; i < num_threads; i++) {
      ph[i] = new Phaser(2);
    }
    for (int i = 0; i < num_threads; i++) {
      final Phaser curr = ph[i];
      final Phaser neighbour = ph[(i + num_threads - 1) % num_threads];
      final int id = i;
      new Thread(new Runnable() {
        @Override
        public void run() {
          JArmus.register(curr);
          JArmus.register(neighbour);
          for (int k = 1; k <= nz - 2; k++) {
            step(k);
            if (id > 0) {
              neighbour.arriveAndAwaitAdvance();
            }
            step2(k);
            if (id < num_threads - 1) {
              curr.arriveAndAwaitAdvance();
            }
View Full Code Here

Examples of java.util.concurrent.Phaser

public class ProducerConsumer2 {
  protected static final int nz = 1000;

  public static void main(String[] args) {
    final int num_threads = 3;
    final Phaser ph[] = new Phaser[num_threads];
    for (int i = 0; i < num_threads; i++) {
      ph[i] = new Phaser(2);
    }
    for (int i = 0; i < num_threads; i++) {
      final Phaser curr = ph[i];
      final Phaser neighbour = ph[(i - 1 + num_threads) % num_threads];
      final int id = i;
      new Thread(new Runnable() {
        @Override
        public void run() {
          JArmus.register(curr);
          JArmus.register(neighbour);
          for (int k = 1; k <= nz - 2; k++) {
            step(k);
            /* we introduce the deadlock by commenting one of the
               boundary conditions */
            if (id > 0) {
              neighbour.arriveAndAwaitAdvance();
            }
            step2(k);
            //if (id < num_threads - 1) {
              curr.arriveAndAwaitAdvance();
            //}
View Full Code Here

Examples of java.util.concurrent.Phaser

public class ProducerConsumer1 {
  protected static final int nz = 1000;

  public static void main(String[] args) {
    final int num_threads = 3;
    final Phaser ph[] = new Phaser[num_threads];
    for (int i = 0; i < num_threads; i++) {
      ph[i] = new Phaser(2);
    }
    for (int i = 0; i < num_threads; i++) {
      final Phaser curr = ph[i];
      final Phaser neighbour = ph[(i - 1 + num_threads) % num_threads];
      final int id = i;
      new Thread(new Runnable() {
        @Override
        public void run() {
          JArmus.register(curr);
          JArmus.register(neighbour);
          for (int k = 1; k <= nz - 2; k++) {
            step(k);
            /* we introduce the deadlock by commenting one of the
               boundary conditions */
            //if (id > 0) {
              neighbour.arriveAndAwaitAdvance();
            //}
            step2(k);
            if (id < num_threads - 1) {
              curr.arriveAndAwaitAdvance();
            }
View Full Code Here

Examples of 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);
        }
      }
    }));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.