81 |
|
final AtomicInteger ai = new AtomicInteger(1); |
82 |
|
Thread t = new Thread(new Runnable() { |
83 |
|
public void run() { |
84 |
< |
while(!ai.compareAndSet(2, 3)) Thread.yield(); |
84 |
> |
while (!ai.compareAndSet(2, 3)) Thread.yield(); |
85 |
|
}}); |
86 |
|
try { |
87 |
|
t.start(); |
90 |
|
assertFalse(t.isAlive()); |
91 |
|
assertEquals(ai.get(), 3); |
92 |
|
} |
93 |
< |
catch(Exception e) { |
93 |
> |
catch (Exception e) { |
94 |
|
unexpectedException(); |
95 |
|
} |
96 |
|
} |
101 |
|
*/ |
102 |
|
public void testWeakCompareAndSet(){ |
103 |
|
AtomicInteger ai = new AtomicInteger(1); |
104 |
< |
while(!ai.weakCompareAndSet(1,2)); |
105 |
< |
while(!ai.weakCompareAndSet(2,-4)); |
104 |
> |
while (!ai.weakCompareAndSet(1,2)); |
105 |
> |
while (!ai.weakCompareAndSet(2,-4)); |
106 |
|
assertEquals(-4,ai.get()); |
107 |
< |
while(!ai.weakCompareAndSet(-4,7)); |
107 |
> |
while (!ai.weakCompareAndSet(-4,7)); |
108 |
|
assertEquals(7,ai.get()); |
109 |
|
} |
110 |
|
|
206 |
|
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
207 |
|
AtomicInteger r = (AtomicInteger) in.readObject(); |
208 |
|
assertEquals(l.get(), r.get()); |
209 |
< |
} catch(Exception e){ |
209 |
> |
} catch (Exception e){ |
210 |
|
unexpectedException(); |
211 |
|
} |
212 |
|
} |