import threading
count = 0
lock = threading.Lock()
pause_event = threading.Event()
def worker():
global count
while True:
with lock:
if count < 100:
count += 1
print(f"Thread {threading.current_thread().name} incremented count to {count}")
if count == 100:
pause_event.clear()
print("Count has reached 100. Pausing all threads.")
else:
pause_event.wait()
threads = []
for i in range(5):
t = threading.Thread(target=worker)
threads.append(t)
t.start()
# 模拟外部信号,当接收到外部信号时,调用以下代码继续线程操作
# pause_event.set()