-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignment8_1.py
37 lines (28 loc) · 907 Bytes
/
Assignment8_1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
Design python application which creates two thread named as even and odd.
Even thread will display first 10 even numbers and odd thread will display first 10 odd numbers.
"""
import threading;
def Even(number, lock):
lock.acquire();
print("\nFirst 10 Even Nos: ");
for i in range(number):
if (i % 2 == 0):
print(i, end=' ');
lock.release();
def Odd(number, lock):
lock.acquire();
print("\nFirst 10 Odd Nos: ");
for i in range(number):
if (i % 2 == 1):
print(i, end=' ');
lock.release();
if __name__ == "__main__":
number = 20;
lock = threading.Lock();
EvenTread = threading.Thread(target=Even, args=(number, lock));
OddThread = threading.Thread(target=Odd, args=(number, lock));
EvenTread.start();
OddThread.start();
EvenTread.join();
OddThread.join();