Class SharedObject<T>
java.lang.Object
edu.rit.pj.reduction.SharedObject<T>
- Type Parameters:
T- Object data type.
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.
- Version:
- 20-Jun-2007
- Author:
- Alan Kaminsky
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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
Modifier and TypeMethodDescriptionbooleancompareAndSet(T expect, T update) Atomically set this reduction variable to the given updated value if the current value equals the expected value.get()Returns this reduction variable's current value.Set this reduction variable to the given value and return the previous value.Combine this reduction variable with the given value using the given operation.voidSet this reduction variable to the given value.toString()Returns a string version of this reduction variable.booleanweakCompareAndSet(T expect, T update) Atomically set this reduction variable to the given updated value if the current value equals the expected value.
-
Constructor Details
-
SharedObject
public SharedObject()Construct a new object reduction variable with the initial value null. -
SharedObject
Construct a new object reduction variable with the given initial value.- Parameters:
initialValue- Initial value.
-
-
Method Details
-
get
-
set
Set this reduction variable to the given value.- Parameters:
value- New value.
-
getAndSet
-
compareAndSet
-
weakCompareAndSet
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
-
toString
-