Class SharedVariable<T extends Serializable>

java.lang.Object
jromp.parallel.var.SharedVariable<T>
Type Parameters:
T - the type of the variable.
All Implemented Interfaces:
Serializable, Variable<T>

public class SharedVariable<T extends Serializable> extends Object implements Variable<T>
A variable that is shared between threads.
See Also:
  • Constructor Details

    • SharedVariable

      public SharedVariable(T value)
      Constructs a new shared variable with the given value.
      Parameters:
      value - the value of the variable.
  • Method Details

    • value

      public T value()
      Description copied from interface: Variable
      Retrieves the value of the variable.
      Specified by:
      value in interface Variable<T extends Serializable>
      Returns:
      the value of the variable.
    • set

      public void set(T value)
      Description copied from interface: Variable
      Sets the value of the variable.
      Specified by:
      set in interface Variable<T extends Serializable>
      Parameters:
      value - the new value to be set.
    • update

      public void update(UnaryOperator<T> operator)
      Description copied from interface: Variable
      Applies the given UnaryOperator to update the value of the variable.
      Specified by:
      update in interface Variable<T extends Serializable>
      Parameters:
      operator - the unary operator to apply.
    • copy

      public SharedVariable<T> copy()
      Description copied from interface: Variable
      Creates a copy of the variable.
      Specified by:
      copy in interface Variable<T extends Serializable>
      Returns:
      a copy of the variable.
    • end

      public void end()
      Description copied from interface: Variable
      Performs any cleanup operations that may be required by the variable.
      Specified by:
      end in interface Variable<T extends Serializable>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toAtomic

      public AtomicVariable<T> toAtomic()
      Converts a SharedVariable to an AtomicVariable. It only creates the atomic variable once and returns the same instance on subsequent calls.
      Returns:
      the AtomicVariable representation of the shared variable.
    • hasAtomic

      public boolean hasAtomic()
      Checks if the shared variable has an atomic variable representation.
      Returns:
      true if the shared variable has an atomic variable, false otherwise.