import threading import time class Mythread(threading.Thread): def run(self): global num if mutex.acquire(): num+=1 print num mutex.release() num=0 mutex=threading.Lock() def test(): for i in range(5): t=Mythread() t.start() if __name__ == '__main__': test() ''' class mythread(threading.Thread): def __init__(self,num): threading.Thread.__init__(self) self.num=num def run(self): print self.num for i in range(5): t=mythread(i) t.start() #t=threading.Thread(target=run,args=(15,20)) #t.start() '''