import threading
number = 0
def func_a():
global number
while True:
lockc.acquire()
if number >= 75:
break
for _ in range(5):
# time.sleep(0.5)
number += 1
print("{}:{}".format(threading.current_thread().name, number))
locka.release()
def func_b():
global number
while True:
locka.acquire()
if number >= 75:
break
for _ in range(5):
# time.sleep(0.5)
number += 1
print("{}:{}".format(threading.current_thread().name, number))
lockb.release()
def func_c():
global number
while True:
lockb.acquire()
if number >= 75:
break
for _ in range(5):
# time.sleep(0.5)
number += 1
print("{}:{}".format(threading.current_thread().name, number))
lockc.release()
if __name__ == "__main__":
locka = threading.Lock()
lockb = threading.Lock()
lockc = threading.Lock()
thread1 = threading.Thread(target=func_a)
thread2 = threading.Thread(target=func_b)
thread3 = threading.Thread(target=func_c)
locka.acquire()
lockb.acquire()
thread1.start()
thread2.start()
thread3.start()
number = 0
def func_a():
global number
while True:
lockc.acquire()
if number >= 75:
break
for _ in range(5):
# time.sleep(0.5)
number += 1
print("{}:{}".format(threading.current_thread().name, number))
locka.release()
def func_b():
global number
while True:
locka.acquire()
if number >= 75:
break
for _ in range(5):
# time.sleep(0.5)
number += 1
print("{}:{}".format(threading.current_thread().name, number))
lockb.release()
def func_c():
global number
while True:
lockb.acquire()
if number >= 75:
break
for _ in range(5):
# time.sleep(0.5)
number += 1
print("{}:{}".format(threading.current_thread().name, number))
lockc.release()
if __name__ == "__main__":
locka = threading.Lock()
lockb = threading.Lock()
lockc = threading.Lock()
thread1 = threading.Thread(target=func_a)
thread2 = threading.Thread(target=func_b)
thread3 = threading.Thread(target=func_c)
locka.acquire()
lockb.acquire()
thread1.start()
thread2.start()
thread3.start()