码迷,mamicode.com
首页 > 编程语言 > 详细

Python 死锁现象

时间:2019-01-14 18:55:11      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:port   rom   pre   release   class   ase   pytho   python   nbsp   

import time
from threading import Thread,Lock,RLock
def f1(locA,locB):
    locA.acquire()
    print(f1>>1号抢到了A锁)
    time.sleep(1)
    locB.acquire()
    print(f1>>1号抢到了B锁)
    locB.release()

    locA.release()
def f2(locA,locB):
    locB.acquire()

    print(f2>>2号抢到了B锁)

    locA.acquire()
    time.sleep(1)
    print(f2>>2号抢到了A锁)
    locA.release()

    locB.release()
if __name__ == __main__:
    locA = Lock()
    locB = Lock()
    t1 = Thread(target=f1,args=(locA,locB))
    t2 = Thread(target=f2,args=(locA,locB))
    t1.start()
    t2.start()

 

Python 死锁现象

标签:port   rom   pre   release   class   ase   pytho   python   nbsp   

原文地址:https://www.cnblogs.com/demons97/p/10268210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!