122 |
|
* compareAndSet in one thread enables another waiting for value |
123 |
|
* to succeed |
124 |
|
*/ |
125 |
< |
public void testCompareAndSetInMultipleThreads() { |
125 |
> |
public void testCompareAndSetInMultipleThreads() throws Exception { |
126 |
|
x = one; |
127 |
|
final AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a; |
128 |
|
try { |
131 |
|
return; |
132 |
|
} |
133 |
|
|
134 |
< |
Thread t = new Thread(new Runnable() { |
135 |
< |
public void run() { |
136 |
< |
while (!a.compareAndSet(AtomicReferenceFieldUpdaterTest.this, two, three)) Thread.yield(); |
137 |
< |
}}); |
138 |
< |
try { |
139 |
< |
t.start(); |
140 |
< |
assertTrue(a.compareAndSet(this, one, two)); |
141 |
< |
t.join(LONG_DELAY_MS); |
142 |
< |
assertFalse(t.isAlive()); |
143 |
< |
assertEquals(a.get(this), three); |
144 |
< |
} |
145 |
< |
catch (Exception e) { |
146 |
< |
unexpectedException(); |
147 |
< |
} |
134 |
> |
Thread t = new Thread(new CheckedRunnable() { |
135 |
> |
public void realRun() { |
136 |
> |
while (!a.compareAndSet(AtomicReferenceFieldUpdaterTest.this, two, three)) |
137 |
> |
Thread.yield(); |
138 |
> |
}}); |
139 |
> |
|
140 |
> |
t.start(); |
141 |
> |
assertTrue(a.compareAndSet(this, one, two)); |
142 |
> |
t.join(LONG_DELAY_MS); |
143 |
> |
assertFalse(t.isAlive()); |
144 |
> |
assertEquals(a.get(this), three); |
145 |
|
} |
146 |
|
|
147 |
|
/** |