Skip to content

Commit 58628c5

Browse files
author
Mofan Zhou
committed
create multiprocessing7
1 parent e091d3a commit 58628c5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import multiprocessing as mp
2+
import time
3+
4+
def job(v, num, l):
5+
l.acquire()
6+
for _ in range(10):
7+
time.sleep(0.1)
8+
v.value += num
9+
print(v.value)
10+
l.release()
11+
12+
def multicore():
13+
l = mp.Lock()
14+
v = mp.Value('i', 0)
15+
p1 = mp.Process(target=job, args=(v, 1, l))
16+
p2 = mp.Process(target=job, args=(v, 3, l))
17+
p1.start()
18+
p2.start()
19+
p1.join()
20+
p2.join()
21+
22+
if __name__ == '__main__':
23+
multicore()
24+
25+
26+

0 commit comments

Comments
 (0)