运维审计系统安全实战:从架构解析到漏洞攻防与加固
2026/6/21 22:24:01
from log import * import threading import time # 共享资源 counter = 0 lock = threading.Lock() def increment(): global counter lock.acquire() try: counter += 1 info("CUrrent thread: {}, Counter: {}".format(threading.current_thread().name, counter)) finally: # 释放锁 lock.release() # 创建10个线程 threads = [] for _ in range(10): t = threading.Thread(target=increment) threads.append(t) t.start() # 等待所有线程完成 for t in threads: t.join()