Created
September 1, 2016 12:39
-
-
Save ants/c90ce6732c38fcdbf3c4a228180e5d39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import RLock, Thread | |
import time | |
running = True | |
def long_lock_loop(mutex): | |
while running: | |
mutex.acquire() | |
print "Long acquired" | |
time.sleep(3) | |
print "Long releasing" | |
mutex.release() | |
def short_lock_loop(mutex): | |
while running: | |
mutex.acquire() | |
print "Short acquired" | |
mutex.release() | |
time.sleep(3) | |
t_lock = RLock() | |
t1 = Thread(target=long_lock_loop, args=(t_lock,)) | |
t2 = Thread(target=short_lock_loop, args=(t_lock,)) | |
t1.start() | |
t2.start() | |
try: | |
while True: | |
time.sleep(60) | |
finally: | |
running = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment