天天看點

Python線程鎖

多線程的優勢:

可以同時運作多個任務

但是當多個線程同時通路共享資料時,可能導緻資料不同步,甚至錯誤!

so,不使用線程鎖, 可能導緻錯誤

購買車票--線程鎖

[root@~]# cat test.py 

結果:

[root@~]# python test.py 

Python線程鎖