Package org.jcsp.lang

Class Bucket

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int bucketCycle
      Barrier uses an even/odd flag because the barrier cannot sync without every process Bucket can happily keep working while old processes are waiting around, so a flag is not enough Instead, a count must be used.
      private java.lang.Object bucketLock
      The monitor lock used for synchronization
      private int nHolding
      The number of processes currently enrolled on this bucket.
    • Constructor Summary

      Constructors 
      Constructor Description
      Bucket()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Bucket[] create​(int n)
      Creates an array of Buckets.
      void fallInto()
      Fall into the bucket.
      int flush()
      Flush the bucket.
      int holding()
      This returns the number of processes currently held in the bucket.
      • Methods inherited from class java.lang.Object

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

      • nHolding

        private int nHolding
        The number of processes currently enrolled on this bucket.
      • bucketLock

        private final java.lang.Object bucketLock
        The monitor lock used for synchronization
      • bucketCycle

        private int bucketCycle
        Barrier uses an even/odd flag because the barrier cannot sync without every process Bucket can happily keep working while old processes are waiting around, so a flag is not enough Instead, a count must be used. Theoretically this is unsafe, but the likelihood of the bucket completing 4 *billion* cycles before the process wakes up is somewhat slim.
    • Constructor Detail

      • Bucket

        public Bucket()
    • Method Detail

      • fallInto

        public void fallInto()
        Fall into the bucket. The process doing this will be blocked until the next flush().
      • flush

        public int flush()
        Flush the bucket. All held processes will be released. It returns the number that were released.

        Returns:
        the number of processes flushed.
      • holding

        public int holding()
        This returns the number of processes currently held in the bucket. Note that this number is volatile - for information only! By the time the invoker of this method receives it, it might have changed (because of further processes falling into the bucket or someone flushing it).

        Returns:
        the number of processes currently held in the bucket.
      • create

        public static Bucket[] create​(int n)
        Creates an array of Buckets.

        Parameters:
        n - the number of Buckets to create in the array
        Returns:
        the array of Buckets