Documentation of 'edu.rit.pj.reduction.SharedObject' Java class
SharedObject
edu.rit.pj.reduction

Class SharedObject<T>

  • Type Parameters:
    T - Object data type.


    public class SharedObject<T>
    extends java.lang.Object
    Class SharedObject provides a reduction variable for a value of an object type.

    Class SharedObject is multiple thread safe. The methods use lock-free atomic compare-and-set.

    Note: Class SharedObject is implemented using class java.util.concurrent.atomic.AtomicReference.

    • Constructor Summary

      Constructors 
      Constructor and Description
      SharedObject()
      Construct a new object reduction variable with the initial value null.
      SharedObject(T initialValue)
      Construct a new object reduction variable with the given initial value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean compareAndSet(T expect, T update)
      Atomically set this reduction variable to the given updated value if the current value equals the expected value.
      T get()
      Returns this reduction variable's current value.
      T getAndSet(T value)
      Set this reduction variable to the given value and return the previous value.
      T reduce(T value, ObjectOp<T> op)
      Combine this reduction variable with the given value using the given operation.
      void set(T value)
      Set this reduction variable to the given value.
      java.lang.String toString()
      Returns a string version of this reduction variable.
      boolean weakCompareAndSet(T expect, T update)
      Atomically set this reduction variable to the given updated value if the current value equals the expected value.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • SharedObject

        public SharedObject()
        Construct a new object reduction variable with the initial value null.
      • SharedObject

        public SharedObject(T initialValue)
        Construct a new object reduction variable with the given initial value.
        Parameters:
        initialValue - Initial value.
    • Method Detail

      • get

        public T get()
        Returns this reduction variable's current value.
        Returns:
        Current value.
      • set

        public void set(T value)
        Set this reduction variable to the given value.
        Parameters:
        value - New value.
      • getAndSet

        public T getAndSet(T value)
        Set this reduction variable to the given value and return the previous value.
        Parameters:
        value - New value.
        Returns:
        Previous value.
      • compareAndSet

        public boolean compareAndSet(T expect,
                                     T update)
        Atomically set this reduction variable to the given updated value if the current value equals the expected value.
        Parameters:
        expect - Expected value.
        update - Updated value.
        Returns:
        True if the update happened, false otherwise.
      • weakCompareAndSet

        public boolean weakCompareAndSet(T expect,
                                         T update)
        Atomically set this reduction variable to the given updated value if the current value equals the expected value. May fail spuriously.
        Parameters:
        expect - Expected value.
        update - Updated value.
        Returns:
        True if the update happened, false otherwise.
      • reduce

        public T reduce(T value,
                        ObjectOp<T> op)
        Combine this reduction variable with the given value using the given operation. The result is stored back into this reduction variable and is returned.
        Parameters:
        value - Value.
        op - Binary operation.
        Returns:
        (This variable) op (value).
      • toString

        public java.lang.String toString()
        Returns a string version of this reduction variable.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String version.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.