#!/usr/bin/python # -*- coding:utf8 -*- from threading import Thread, Lock import random def test_thread(): # 线程间的通信 # 使用锁来控制共享资源的访问 a = 0 n = 10000000 lock = Lock() def imcr(n): global a for i in range(n): lock.acquire() # 可以写成with lock: a += 1 # a+…