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