def test_mutex_try_acquire(): m = Mutex() # Trying to acquire the lock should succeed assert m.try_acquire() # Assert that the lock is truly held now assert m.debug_is_locked() # Clean up m.release()
def test_mutex_try_acquire(): m = Mutex() # Trying to acquire the lock should succeed assert m.try_acquire() # Assert that the lock is truly held now assert m.debug_is_locked() # Clean up m.release()
def test_cvar_notify_locked(): # Tests the same thing, but with the lock held. m = Mutex() cv = ConditionVarFull(m) m.acquire() cv.notify() m.release() m.acquire() cv.notify_all() m.release() del cv
def test_mutex_acquire_release(): m = Mutex() m.acquire() # Assert that the lock is truly held now assert m.debug_is_locked() # Release the lock m.release() # Make sure the lock is properly released assert m.try_acquire() # Clean up m.release()
def test_mutex_acquire_release(): m = Mutex() m.acquire() # Assert that the lock is truly held now assert m.debug_is_locked() # Release the lock m.release() # Make sure the lock is properly released assert m.try_acquire() # Clean up m.release()
def test_cvar_notify_thread(num_threads): # Tests notify() with some number of threads waiting. m = Mutex() cv = ConditionVarFull(m) # We prematurely notify, so that we can test that it's not doing anything. m.acquire() cv.notify() state = {'waiting': 0} def wait_thread(): m.acquire() state['waiting'] += 1 cv.wait() state['waiting'] -= 1 m.release() # Start the threads, and yield to it, giving it a chance to mess up. threads = [] for i in range(num_threads): thread = core.PythonThread(wait_thread, (), "", "") thread.start(core.TP_high, True) # Yield until all of the threads are waiting for the condition variable. for i in range(1000): m.release() yield_thread() m.acquire() if state['waiting'] == num_threads: break assert state['waiting'] == num_threads # OK, now signal it, and yield. One thread must be unblocked per notify. for i in range(num_threads): cv.notify() expected_waiters = num_threads - i - 1 for j in range(1000): m.release() yield_thread() m.acquire() if state['waiting'] == expected_waiters: break assert state['waiting'] == expected_waiters m.release() for thread in threads: thread.join() cv = None