2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
< |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
< |
* Pat Fisher, Mike Judd. |
5 |
> |
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
> |
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
|
import java.util.concurrent.atomic.*; |
76 |
|
assertEquals(one,a.get(this)); |
77 |
|
a.set(this,two); |
78 |
|
assertEquals(two,a.get(this)); |
79 |
< |
a.set(this,-3); |
80 |
< |
assertEquals(-3,a.get(this)); |
81 |
< |
|
79 |
> |
a.set(this,m3); |
80 |
> |
assertEquals(m3,a.get(this)); |
81 |
|
} |
82 |
+ |
|
83 |
+ |
/** |
84 |
+ |
* get returns the last value lazySet by same thread |
85 |
+ |
*/ |
86 |
+ |
public void testGetLazySet(){ |
87 |
+ |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a; |
88 |
+ |
try { |
89 |
+ |
a = AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdaterTest.class, Integer.class, "x"); |
90 |
+ |
} catch (RuntimeException ok) { |
91 |
+ |
return; |
92 |
+ |
} |
93 |
+ |
x = one; |
94 |
+ |
assertEquals(one,a.get(this)); |
95 |
+ |
a.lazySet(this,two); |
96 |
+ |
assertEquals(two,a.get(this)); |
97 |
+ |
a.lazySet(this,m3); |
98 |
+ |
assertEquals(m3,a.get(this)); |
99 |
+ |
} |
100 |
+ |
|
101 |
|
/** |
102 |
|
* compareAndSet succeeds in changing value if equal to expected else fails |
103 |
|
*/ |
149 |
|
|
150 |
|
/** |
151 |
|
* repeated weakCompareAndSet succeeds in changing value when equal |
152 |
< |
* to expected |
152 |
> |
* to expected |
153 |
|
*/ |
154 |
|
public void testWeakCompareAndSet(){ |
155 |
|
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a; |