import threading
class myThread(threading.Thread):
def __init__(self,a,c,d,):
super().__init__(self)
self.a=a
self.c=c
self.d=d
self.Lock=threading.Lock()
def run(self):
print('线程开始'+self.a)
self.Lock.acquire()#线程加锁
mylist(self.c,self.d)
self.Lock.release()#线程释放
print('线程结束'+self.a)
def mylist(c,d):
for i in range(c,d):
print(i)
a=’thread1’
b=’thread2’
c=1
d=100
thread1=myThread(a,c,d)
thread2=myThread(b,d+c,d*2)
thread1.start()
thread2.start()
thread1.join()
thread2.join()