- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadSync.py
More file actions
Latest commit
31 lines (26 loc) · 515 Bytes
/
Copy pathThreadSync.py
File metadata and controls
31 lines (26 loc) · 515 Bytes
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
importthreading
importtime
x=8192
lock=threading.Lock()
defdouble():
globalx, lock
lock.acquire()
whilex<16384:
x*=2
print(x)
time.sleep(1)
print("Reached the maximum!")
lock.release()
defhalve():
globalx, lock
lock.acquire()
whilex>1:
x/=2
print(x)
time.sleep(1)
print("Reached the minimum!")
lock.release()
t1=threading.Thread(target=halve)
t2=threading.Thread(target=double)
t1.start()
t2.start()