Thread1.
py
import threading
import time
def task1():
for i in range(5):
print('Rama-',i+1)
[Link](0.5)
def task2():
for i in range(5):
print('Sita-',i+1)
[Link](0.5)
#Creation of Thread object
th1=[Link](target=task1)
th2=[Link](target=task2)
t1=[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
t2=[Link]()
print('Time Taken: ',t2-t1)
[Link]:
import threading
import time
class MyThread1([Link]):
def run(self):
for i in range(5):
print('Rama-',i+1)
[Link](0.5)
class MyThread2([Link]):
def run(self):
for i in range(5):
print('Sita-',i+1)
[Link](0.5)
t1=MyThread1()
t2=MyThread2()
[Link]()
[Link]()
import threading
import time
class Person1([Link]):
def run(self):
global lock
[Link]()
print('Person-1 using the meeting room')
[Link](1)
print('Person-1 vacating the meeting room')
[Link]()
class Person2([Link]):
def run(self):
global lock
[Link]()
print('Person-2 using the meeting room')
[Link](1)
print('Person-2 vacating the meeting room')
[Link]()
lock=[Link]()
t1=Person1()
t2=Person2()
[Link]()
[Link]()