bloritsch    01/10/31 06:08:29

  Modified:    src/test/org/apache/avalon/excalibur/concurrent/test
                        ReadWriteLockTestCase.java
  Log:
  Apply fix to ReadWriteLock fromAvi Drissman ([EMAIL PROTECTED])
  
  Revision  Changes    Path
  1.5       +57 -0     
jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/concurrent/test/ReadWriteLockTestCase.java
  
  Index: ReadWriteLockTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-excalibur/src/test/org/apache/avalon/excalibur/concurrent/test/ReadWriteLockTestCase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReadWriteLockTestCase.java        2001/10/25 16:00:48     1.4
  +++ ReadWriteLockTestCase.java        2001/10/31 14:08:28     1.5
  @@ -309,6 +309,63 @@
           assertTrue( "Could not aquire a write lock after releasing the 
lock.",
                       lock.tryAquireWrite() );
       }
  +
  +    /**
  +     * Tests a condition pointed out to me (L.Sutic) by Avi Drissman
  +     * <a href="[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>. If you hold
  +     * a read lock, and a thread waiting for a write lock is interrupted,
  +     * there is no way to aquire a read lock again.
  +     *
  +     * (This condition is fixed, 2001-10-31.)
  +     */
  +    public void testDeadLock () throws Exception {
  +        ReadWriteLock lock = new ReadWriteLock();
  +        TriesReadLock rla = new TriesReadLock( lock );
  +        TriesReadLock rlb = new TriesReadLock( lock );
  +        TriesWriteLock wla = new TriesWriteLock( lock );
  +        TriesWriteLock wlb = new TriesWriteLock( lock );
  +
  +        //
  +        // Grab a read lock.
  +        //
  +        rla.start();
  +        Thread.currentThread().sleep( 100 );
  +        assertTrue( rla.hasSuccess() );
  +
  +        //
  +        // Try to grab a write lock. (The attempt stalls,
  +        // because we are holding a read lock.)
  +        //
  +        wla.start();
  +        Thread.currentThread().sleep( 100 );
  +        assertTrue( !wla.hasSuccess() );
  +
  +        //
  +        // Interupt the thread waiting for the write lock...
  +        //
  +        wla.interrupt();
  +
  +        //
  +        // ...and release the read lock.
  +        //
  +        lock.release();
  +
  +        //
  +        // Right, we are in the condition described by Drissman.
  +        // Now try to aquire, in turn, a read and a write lock.
  +        // Before the fix, the assertion immediately below
  +        // would fail.
  +        //
  +        rlb.start();
  +        Thread.currentThread().sleep( 100 );
  +        assertTrue( rlb.hasSuccess() );
  +        lock.release();
  +
  +        wlb.start();
  +        Thread.currentThread().sleep( 100 );
  +        assertTrue( wlb.hasSuccess() );
  +        lock.release();
  +     }
   }
   
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to