Exemple #1
0
 def test_demotion_with_blocked_writer(self):
     lock = RWLock()
     writer = LockingThread(lock.exclusive)
     try:
         with lock.exclusive:
             writer.start()
             writer.ready.wait()
             # Ensure that writer is blocked
             if writer.acquired.wait(0.5):
                 raise RuntimeError("Writer could acquire the lock while "
                                    "holding a write lock")
             lock.acquireRead()
             # I hold both a read lock and a write lock now
         # I release the write lock. Having read lock, writer must block
         self.assertFalse(
             writer.acquired.wait(0.5),
             "Writer acquired the lock while holding a read "
             "lock")
     finally:
         lock.release()
         try:
             # Writer must acquire now
             self.assertTrue(writer.acquired.wait(0.5))
         finally:
             writer.stop()
Exemple #2
0
 def test_demotion_no_waiters(self):
     lock = RWLock()
     try:
         with lock.exclusive:
             lock.acquireRead()
     finally:
         lock.release()
Exemple #3
0
 def test_demotion_no_waiters(self):
     lock = RWLock()
     try:
         with lock.exclusive:
             lock.acquireRead()
     finally:
         lock.release()
Exemple #4
0
 def test_demotion_with_blocked_reader(self):
     lock = RWLock()
     reader = LockingThread(lock.shared)
     try:
         with lock.exclusive:
             reader.start()
             reader.ready.wait()
             # Ensure that reader is blocked
             if reader.acquired.wait(0.5):
                 raise RuntimeError("Reader could acquire the lock while "
                                    "holding a write lock")
             lock.acquireRead()
             # I hold both a read lock and a write lock now
         # I released the write lock. Having read lock, reader shold get the
         # lock.
         self.assertTrue(reader.acquired.wait(0.5),
                         "Reader could not acuire the lock")
     finally:
         lock.release()
         reader.stop()
Exemple #5
0
 def test_demotion_with_blocked_reader(self):
     lock = RWLock()
     reader = LockingThread(lock.shared)
     try:
         with lock.exclusive:
             reader.start()
             reader.ready.wait()
             # Ensure that reader is blocked
             if reader.acquired.wait(0.5):
                 raise RuntimeError("Reader could acquire the lock while "
                                    "holding a write lock")
             lock.acquireRead()
             # I hold both a read lock and a write lock now
         # I released the write lock. Having read lock, reader should get
         # the lock.
         self.assertTrue(reader.acquired.wait(0.5),
                         "Reader could not acuire the lock")
     finally:
         lock.release()
         reader.stop()
Exemple #6
0
 def test_demotion_with_blocked_writer(self):
     lock = RWLock()
     writer = LockingThread(lock.exclusive)
     try:
         with lock.exclusive:
             writer.start()
             writer.ready.wait()
             # Ensure that writer is blocked
             if writer.acquired.wait(0.5):
                 raise RuntimeError("Writer could acquire the lock while "
                                    "holding a write lock")
             lock.acquireRead()
             # I hold both a read lock and a write lock now
         # I release the write lock. Having read lock, writer must block
         self.assertFalse(writer.acquired.wait(0.5),
                          "Writer acquired the lock while holding a read "
                          "lock")
     finally:
         lock.release()
         try:
             # Writer must acquire now
             self.assertTrue(writer.acquired.wait(0.5))
         finally:
             writer.stop()