lock锁住没用
老师为什么我按照这个程序例子敲了一边,lock锁住没用,还是错误的money
lock=threading.Lock() #存钱1000 def deposit(balance): for i in range(100): time.sleep(0.01) lock.acquire() balance.value += 1000 print(balance.value) lock.release() #取钱1000 def withdraw(balance): for i in range(100): time.sleep(0.01) lock.acquire() balance.value -= 1000 print(balance.value) lock.release() if __name__=="__main__": balance=Value('i',2000) print("初始余额",balance.value) t1 = Process(target=deposit, name="thread1", args=(balance,)) t2 = Process(target=withdraw, name="thread2", args=(balance,)) t1.start() t2.start() t1.join() t2.join() print("最终余额:",balance.value)