-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreaded test
More file actions
64 lines (43 loc) · 1.02 KB
/
MultiThreaded test
File metadata and controls
64 lines (43 loc) · 1.02 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from threading import Thread
from multiprocessing import Process
import time
result = 3
def returnone():
while True:
global result
result += 1
time.sleep(0.1)
def addthree():
while True:
global result
print('result is : ', result)
time.sleep(0.1)
def minusone():
global result
while True:
if result > -500:
result -= 5
time.sleep(0.1)
t1 = Thread(target=returnone)
t2 = Thread(target=addthree)
t3 = Thread(target=minusone)
t1.start()
# time.sleep(5)
t2.start()
t3.start()
# from threading import Thread
# import time
# a = 0 #global variable
# def thread1(threadname):
# #global a # Optional if you treat a as read-only
# while True:
# print(a)
# def thread2(threadname):
# global a
# while True:
# a += 1
# time.sleep(0.01)
# thread1 = Thread( target=thread1, args=("Thread-1", ) )
# thread2 = Thread( target=thread2, args=("Thread-2", ) )
# thread1.start()
# thread2.start()