-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyThread1
48 lines (39 loc) · 1.04 KB
/
MyThread1
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
38
39
40
41
42
43
44
45
46
47
#import threading
from threading import Thread
from time import time,sleep
from random import randint
count = 0
def increment():
global count
while True:
print("INSIDE increment enterd")
sleept = randint(1,3)
print("INSIDE increment going to sleep for ", sleept)
sleep(sleept)
print("INSIDE increment sleep completed ")
print("INSIDE increment updating count")
count += 1
def decrement():
global count
while True:
print("INSIDE decrement enterd")
sleept = randint(1,5)
print("INSIDE decrement going to sleep for",sleept)
sleep(sleept)
print("INSIDE decrement sleep completed")
print("INSIDE decrement updating count")
count -= 1
def counter():
while True:
print("INSIDE Counter")
print(count)
sleep(1)
def main():
t1 = Thread(target=increment)
t2 = Thread(target=decrement)
t3 = Thread(target=counter)
t1.start()
t2.start()
t3.start()
if __name__ == '__main__':
main()