import threading ,time a = 5 alock = threading.Lock() b = 5 block = threading.Lock() def thread1calc(): print "thread1 acquiring lock a" alock.acquire() time.sleep(5) print "thread1 acquiring lock b" block.acquire() a+=5 b+=5 print "thread1 releasing both locks" block.release() alock.release() def thread2calc(): print "thread2 acquiring lock b" block.acquire() time.sleep(5) print "thread2 acquiring lock a" alock.acquire() time.sleep(5) a+=10 b+=10 print "thread2 releasing both locks" block.release() alock.release() t = threading.Thread(target = thread1calc) t.setDaemon(1) t.start() t = threading.Thread(target = thread2calc) t.setDaemon(2) t.start() while 1: time.sleep(300)
thread1 acquiring lock a thread2 acquiring lock b thread1 acquiring lock b thread2 acquiring lock a
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有