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

Comparing jsr166/src/test/tck/LockSupportTest.java (file contents):
Revision 1.16 by jsr166, Wed Oct 6 04:05:42 2010 UTC vs.
Revision 1.17 by jsr166, Sun Oct 10 18:15:10 2010 UTC

# Line 156 | Line 156 | public class LockSupportTest extends JSR
156              public void realRun() {
157                  assertFalse(Thread.currentThread().isInterrupted());
158                  threadStarted.countDown();
159 <                LockSupport.park();
160 <                assertTrue(Thread.currentThread().isInterrupted());
159 >                do {
160 >                    LockSupport.park();
161 >                    // park may return spuriously
162 >                } while (! Thread.currentThread().isInterrupted());
163              }});
164  
165          threadStarted.await();
# Line 176 | Line 178 | public class LockSupportTest extends JSR
178                  long d = new Date().getTime() + LONG_DELAY_MS;
179                  long nanos = LONG_DELAY_MS * 1000L * 1000L;
180                  long t0 = System.nanoTime();
181 +                assertFalse(Thread.currentThread().isInterrupted());
182                  threadStarted.countDown();
183 <                LockSupport.parkUntil(d);
183 >                do {
184 >                    LockSupport.parkUntil(d);
185 >                    // parkUntil may return spuriously
186 >                } while (! Thread.currentThread().isInterrupted());
187                  assertTrue(System.nanoTime() - t0 < nanos);
188              }});
189  
# Line 196 | Line 202 | public class LockSupportTest extends JSR
202              public void realRun() {
203                  long nanos = LONG_DELAY_MS * 1000L * 1000L;
204                  long t0 = System.nanoTime();
205 +                assertFalse(Thread.currentThread().isInterrupted());
206                  threadStarted.countDown();
207 <                LockSupport.parkNanos(nanos);
207 >                do {
208 >                    LockSupport.parkNanos(nanos);
209 >                    // parkNanos may return spuriously
210 >                } while (! Thread.currentThread().isInterrupted());
211                  assertTrue(System.nanoTime() - t0 < nanos);
212              }});
213  
# Line 243 | Line 253 | public class LockSupportTest extends JSR
253                  long d = new Date().getTime() + LONG_DELAY_MS;
254                  long nanos = LONG_DELAY_MS * 1000L * 1000L;
255                  long t0 = System.nanoTime();
256 +                assertTrue(Thread.currentThread().isInterrupted());
257                  LockSupport.parkUntil(d);
258                  assertTrue(System.nanoTime() - t0 < nanos);
259 +                assertTrue(Thread.currentThread().isInterrupted());
260              }});
261  
262          threadStarted.await();
# Line 266 | Line 278 | public class LockSupportTest extends JSR
278                      Thread.yield();
279                  long nanos = LONG_DELAY_MS * 1000L * 1000L;
280                  long t0 = System.nanoTime();
281 +                assertTrue(Thread.currentThread().isInterrupted());
282                  LockSupport.parkNanos(nanos);
283                  assertTrue(System.nanoTime() - t0 < nanos);
284 +                assertTrue(Thread.currentThread().isInterrupted());
285              }});
286  
287          threadStarted.await();
# Line 282 | Line 296 | public class LockSupportTest extends JSR
296      public void testParkNanosTimesOut() throws InterruptedException {
297          Thread t = newStartedThread(new CheckedRunnable() {
298              public void realRun() {
299 <                final long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
300 <                long t0 = System.nanoTime();
301 <                LockSupport.parkNanos(timeoutNanos);
302 <                assertTrue(System.nanoTime() - t0 >= timeoutNanos);
299 >                for (;;) {
300 >                    long timeoutNanos = SHORT_DELAY_MS * 1000L * 1000L;
301 >                    long t0 = System.nanoTime();
302 >                    LockSupport.parkNanos(timeoutNanos);
303 >                    // parkNanos may return spuriously
304 >                    if (System.nanoTime() - t0 >= timeoutNanos)
305 >                        return;
306 >                }
307              }});
308  
309          awaitTermination(t, MEDIUM_DELAY_MS);
# Line 298 | Line 316 | public class LockSupportTest extends JSR
316      public void testParkUntilTimesOut() throws InterruptedException {
317          Thread t = newStartedThread(new CheckedRunnable() {
318              public void realRun() {
319 <                long d = new Date().getTime() + SHORT_DELAY_MS;
320 <                // beware of rounding
321 <                long timeoutNanos = (SHORT_DELAY_MS - 1) * 1000L * 1000L;
322 <                long t0 = System.nanoTime();
323 <                LockSupport.parkUntil(d);
324 <                assertTrue(System.nanoTime() - t0 >= timeoutNanos);
319 >                for (;;) {
320 >                    long d = new Date().getTime() + SHORT_DELAY_MS;
321 >                    // beware of rounding
322 >                    long timeoutNanos = (SHORT_DELAY_MS - 1) * 1000L * 1000L;
323 >                    long t0 = System.nanoTime();
324 >                    LockSupport.parkUntil(d);
325 >                    // parkUntil may return spuriously
326 >                    if (System.nanoTime() - t0 >= timeoutNanos)
327 >                        return;
328 >                }
329              }});
330  
331          awaitTermination(t, MEDIUM_DELAY_MS);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines