本文实例讲述了Python实现的多线程同步与互斥锁功能。分享给大家供大家参考,具体如下:
#! /usr/bin/env python
#coding=utf-8
import threading
import time
'''
#1、不加锁
num = 0
class MyThread(threading.Thread):
def run(self):
global num
time.sleep(1) #一定要sleep!!!
num = num + 1
msg = self.name + ' num is ---- ' + str(num)
p