@Test public void testReadWriteDeadlock() throws Exception {
    System.out.println("testReadWriteDeadlock constructing deadlock:");

    SimpleAction p0_read = new SimpleAction(p0, Permissions.READ_ONLY);
    SimpleAction p1_read = new SimpleAction(p1, Permissions.READ_ONLY);
    SimpleAction p1_write = new SimpleAction(p1, Permissions.READ_WRITE);
    SimpleAction p0_write = new SimpleAction(p0, Permissions.READ_WRITE);
    
    LockGrabber lg1 = startGrabber(tid1, new SimpleAction[] {p0_read, p1_write}); 
    LockGrabber lg2 = startGrabber(tid2, new SimpleAction[] {p1_read, p0_write}); 

    while (true) 
    {
      Thread.sleep(POLL_INTERVAL);

      assertFalse(lg1.acquired() && lg2.acquired());
      if (lg1.acquired() && !lg2.acquired()) break;
      if (!lg1.acquired() && lg2.acquired()) break;

      if (lg1.getError() != null) {
    	lg1.stop();
        bp.transactionComplete(tid1);
        Thread.sleep(rand.nextInt(WAIT_INTERVAL));

        tid1 = new TransactionId();
        lg1 = startGrabber(tid1, new SimpleAction[] {p0_read, p1_write});
      }

      if (lg2.getError() != null) {
    	lg2.stop();
        bp.transactionComplete(tid2);
        Thread.sleep(rand.nextInt(WAIT_INTERVAL));

        tid2 = new TransactionId();
        lg2 = startGrabber(tid2, new SimpleAction[] {p1_read, p0_write});
      }
    }

    System.out.println("testReadWriteDeadlock resolved deadlock");
  }