Package org.jcsp.lang

Class Barrier

    • Constructor Summary

      Constructors 
      Constructor Description
      Barrier()
      Construct a barrier initially associated with no processes.
      Barrier​(int nEnrolled)
      Construct a barrier (initially) associated with nEnrolled processes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void enroll()
      A process may enroll only if it is resigned.
      void reset​(int nEnrolled)
      Reset this barrier to be associated with nEnrolled processes.
      void resign()
      A process may resign only if it is enrolled.
      void sync()
      Synchronise the invoking process on this barrier.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Barrier

        public Barrier()
        Construct a barrier initially associated with no processes.
      • Barrier

        public Barrier​(int nEnrolled)
        Construct a barrier (initially) associated with nEnrolled processes. It is the responsibility of the constructing process to pass this (by constructor or set method) to each process that will be synchronising on the barrier, before firing up those processes.

        Parameters:
        nEnrolled - the number of processes (initially) associated with this barrier.

        Throws:
        java.lang.IllegalArgumentException - if nEnrolled < 0.
    • Method Detail

      • reset

        public void reset​(int nEnrolled)
        Reset this barrier to be associated with nEnrolled processes. This must only be done at a time when no processes are active on the barrier. It is the responsibility of the invoking process to pass this barrier (by constructor or set method) to each process that will be synchronising on the barrier, before firing up those processes.

        Parameters:
        nEnrolled - the number of processes reset to this barrier.

        Throws:
        java.lang.IllegalArgumentException - if nEnrolled < 0.
      • sync

        public void sync()
        Synchronise the invoking process on this barrier. Any process synchronising on this barrier will be blocked until all processes associated with the barrier have synchronised (or resigned).
      • enroll

        public void enroll()
        A process may enroll only if it is resigned. A re-enrolled process may resume offering to synchronise on this barrier (until a subsequent resign). Other processes cannot complete the barrier (represented by this front-end) without participation by the re-enrolled process.

        Note: timing re-enrollment on a barrier usually needs some care. If the barrier is being used for synchronising phases of execution between a set of processes, it is crucial that re-enrollment occurs in an appropriate (not arbitrary) phase. If the trigger for re-enrollment comes from another enrolled process, that process should be in such an appropriate phase. The resigned process should re-enroll and, then, acknowledge the trigger. The triggering process should wait for that acknowledgement. If the decision to re-enroll is internal (e.g. following a timeout), a buddy process, enrolled on the barrier, should be asked to provide that trigger when in an appropriate phase. The buddy process, perhaps specially built just for this purpose, polls a service channel for that question when in that phase.

        Warning: the rule in the first sentence above is the responsibility of the designer -- it is not checked by implementation. If not honoured, things will go wrong.

      • resign

        public void resign()
        A process may resign only if it is enrolled. A resigned process may not offer to synchronise on this barrier (until a subsequent enroll). Other processes can complete the barrier (represented by this front-end) without participation by the resigned process.

        Unless all processes synchronising on this barrier terminate in the same phase, it is usually appropriate for a terminating process to resign first. Otherwise, its sibling processes will never be able to complete another synchronisation.

        Warning: the rules in the first two sentences above are the responsibility of the designer -- they are not checked by implementation. If not honoured, things will go wrong.

        Throws:
        BarrierError - if not enrolled (but this is not always detected).