93 |
|
* compareAndSet in one thread enables another waiting for reference value |
94 |
|
* to succeed |
95 |
|
*/ |
96 |
< |
public void testCompareAndSetInMultipleThreads() { |
96 |
> |
public void testCompareAndSetInMultipleThreads() throws Exception { |
97 |
|
final AtomicMarkableReference ai = new AtomicMarkableReference(one, false); |
98 |
< |
Thread t = new Thread(new Runnable() { |
99 |
< |
public void run() { |
100 |
< |
while (!ai.compareAndSet(two, three, false, false)) Thread.yield(); |
101 |
< |
}}); |
102 |
< |
try { |
103 |
< |
t.start(); |
104 |
< |
assertTrue(ai.compareAndSet(one, two, false, false)); |
105 |
< |
t.join(LONG_DELAY_MS); |
106 |
< |
assertFalse(t.isAlive()); |
107 |
< |
assertEquals(ai.getReference(), three); |
108 |
< |
assertFalse(ai.isMarked()); |
109 |
< |
} |
110 |
< |
catch (Exception e) { |
111 |
< |
unexpectedException(); |
112 |
< |
} |
98 |
> |
Thread t = new Thread(new CheckedRunnable() { |
99 |
> |
public void realRun() { |
100 |
> |
while (!ai.compareAndSet(two, three, false, false)) |
101 |
> |
Thread.yield(); |
102 |
> |
}}); |
103 |
> |
|
104 |
> |
t.start(); |
105 |
> |
assertTrue(ai.compareAndSet(one, two, false, false)); |
106 |
> |
t.join(LONG_DELAY_MS); |
107 |
> |
assertFalse(t.isAlive()); |
108 |
> |
assertEquals(ai.getReference(), three); |
109 |
> |
assertFalse(ai.isMarked()); |
110 |
|
} |
111 |
|
|
112 |
|
/** |
113 |
|
* compareAndSet in one thread enables another waiting for mark value |
114 |
|
* to succeed |
115 |
|
*/ |
116 |
< |
public void testCompareAndSetInMultipleThreads2() { |
116 |
> |
public void testCompareAndSetInMultipleThreads2() throws Exception { |
117 |
|
final AtomicMarkableReference ai = new AtomicMarkableReference(one, false); |
118 |
< |
Thread t = new Thread(new Runnable() { |
119 |
< |
public void run() { |
120 |
< |
while (!ai.compareAndSet(one, one, true, false)) Thread.yield(); |
121 |
< |
}}); |
122 |
< |
try { |
123 |
< |
t.start(); |
124 |
< |
assertTrue(ai.compareAndSet(one, one, false, true)); |
125 |
< |
t.join(LONG_DELAY_MS); |
126 |
< |
assertFalse(t.isAlive()); |
127 |
< |
assertEquals(ai.getReference(), one); |
128 |
< |
assertFalse(ai.isMarked()); |
129 |
< |
} |
133 |
< |
catch (Exception e) { |
134 |
< |
unexpectedException(); |
135 |
< |
} |
118 |
> |
Thread t = new Thread(new CheckedRunnable() { |
119 |
> |
public void realRun() { |
120 |
> |
while (!ai.compareAndSet(one, one, true, false)) |
121 |
> |
Thread.yield(); |
122 |
> |
}}); |
123 |
> |
|
124 |
> |
t.start(); |
125 |
> |
assertTrue(ai.compareAndSet(one, one, false, true)); |
126 |
> |
t.join(LONG_DELAY_MS); |
127 |
> |
assertFalse(t.isAlive()); |
128 |
> |
assertEquals(ai.getReference(), one); |
129 |
> |
assertFalse(ai.isMarked()); |
130 |
|
} |
131 |
|
|
132 |
|
/** |