--- jsr166/src/test/tck/ReentrantReadWriteLockTest.java 2005/01/20 00:39:13 1.21 +++ jsr166/src/test/tck/ReentrantReadWriteLockTest.java 2005/05/03 16:02:00 1.22 @@ -747,32 +747,61 @@ public class ReentrantReadWriteLockTest } } + /** A helper class for uninterruptible wait tests */ + class UninterruptableThread extends Thread { + private Lock lock; + private Condition c; + + public volatile boolean canAwake = false; + public volatile boolean interrupted = false; + public volatile boolean lockStarted = false; + + public UninterruptableThread(Lock lock, Condition c) { + this.lock = lock; + this.c = c; + } + + public synchronized void run() { + lock.lock(); + lockStarted = true; + + while (!canAwake) { + c.awaitUninterruptibly(); + } + + interrupted = isInterrupted(); + lock.unlock(); + } + } + /** * awaitUninterruptibly doesn't abort on interrupt */ public void testAwaitUninterruptibly() { - final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); + final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); final Condition c = lock.writeLock().newCondition(); - Thread t = new Thread(new Runnable() { - public void run() { - lock.writeLock().lock(); - c.awaitUninterruptibly(); - lock.writeLock().unlock(); - } - }); + UninterruptableThread thread = new UninterruptableThread(lock.writeLock(), c); try { - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); + thread.start(); + + while (!thread.lockStarted) { + Thread.sleep(100); + } + lock.writeLock().lock(); - c.signal(); - lock.writeLock().unlock(); - assert(t.isInterrupted()); - t.join(SHORT_DELAY_MS); - assertFalse(t.isAlive()); - } - catch (Exception ex) { + try { + thread.interrupt(); + thread.canAwake = true; + c.signal(); + } finally { + lock.writeLock().unlock(); + } + + thread.join(); + assertTrue(thread.interrupted); + assertFalse(thread.isAlive()); + } catch (Exception ex) { unexpectedException(); } }