Package jromp.parallel.var
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>
A variable that is shared between threads.
- See Also:
-
Constructor Summary
ConstructorDescriptionSharedVariable
(T value) Constructs a new shared variable with the given value. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a copy of the variable.void
end()
Performs any cleanup operations that may be required by the variable.boolean
Checks if the shared variable has an atomic variable representation.void
Sets the value of the variable.toAtomic()
Converts aSharedVariable
to anAtomicVariable
.toString()
void
update
(UnaryOperator<T> operator) Applies the givenUnaryOperator
to update the value of the variable.value()
Retrieves the value of the variable.
-
Constructor Details
-
SharedVariable
Constructs a new shared variable with the given value.- Parameters:
value
- the value of the variable.
-
-
Method Details
-
value
Description copied from interface:Variable
Retrieves the value of the variable.- Specified by:
value
in interfaceVariable<T extends Serializable>
- Returns:
- the value of the variable.
-
set
Description copied from interface:Variable
Sets the value of the variable.- Specified by:
set
in interfaceVariable<T extends Serializable>
- Parameters:
value
- the new value to be set.
-
update
Description copied from interface:Variable
Applies the givenUnaryOperator
to update the value of the variable.- Specified by:
update
in interfaceVariable<T extends Serializable>
- Parameters:
operator
- the unary operator to apply.
-
copy
Description copied from interface:Variable
Creates a copy of the variable.- Specified by:
copy
in interfaceVariable<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 interfaceVariable<T extends Serializable>
-
toString
-
toAtomic
Converts aSharedVariable
to anAtomicVariable
. 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.
-