ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicStampedReferenceTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicStampedReferenceTest.java (file contents):
Revision 1.10 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.12 by jsr166, Tue Nov 17 06:58:50 2009 UTC

# Line 93 | Line 93 | public class AtomicStampedReferenceTest
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 AtomicStampedReference ai = new AtomicStampedReference(one, 0);
98 <        Thread t = new Thread(new Runnable() {
99 <                public void run() {
100 <                    while (!ai.compareAndSet(two, three, 0, 0)) Thread.yield();
101 <                }});
102 <        try {
103 <            t.start();
104 <            assertTrue(ai.compareAndSet(one, two, 0, 0));
105 <            t.join(LONG_DELAY_MS);
106 <            assertFalse(t.isAlive());
107 <            assertEquals(ai.getReference(), three);
108 <            assertEquals(ai.getStamp(), 0);
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, 0, 0))
101 >                    Thread.yield();
102 >            }});
103 >
104 >        t.start();
105 >        assertTrue(ai.compareAndSet(one, two, 0, 0));
106 >        t.join(LONG_DELAY_MS);
107 >        assertFalse(t.isAlive());
108 >        assertEquals(ai.getReference(), three);
109 >        assertEquals(ai.getStamp(), 0);
110      }
111  
112      /**
113       * compareAndSet in one thread enables another waiting for stamp value
114       * to succeed
115       */
116 <    public void testCompareAndSetInMultipleThreads2() {
116 >    public void testCompareAndSetInMultipleThreads2() throws Exception {
117          final AtomicStampedReference ai = new AtomicStampedReference(one, 0);
118 <        Thread t = new Thread(new Runnable() {
119 <                public void run() {
120 <                    while (!ai.compareAndSet(one, one, 1, 2)) Thread.yield();
121 <                }});
122 <        try {
123 <            t.start();
124 <            assertTrue(ai.compareAndSet(one, one, 0, 1));
125 <            t.join(LONG_DELAY_MS);
126 <            assertFalse(t.isAlive());
127 <            assertEquals(ai.getReference(), one);
128 <            assertEquals(ai.getStamp(), 2);
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, 1, 2))
121 >                    Thread.yield();
122 >            }});
123 >
124 >        t.start();
125 >        assertTrue(ai.compareAndSet(one, one, 0, 1));
126 >        t.join(LONG_DELAY_MS);
127 >        assertFalse(t.isAlive());
128 >        assertEquals(ai.getReference(), one);
129 >        assertEquals(ai.getStamp(), 2);
130      }
131  
132      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines