-
-
Save inv2004/11e2986b23042c009a48272b475acda2 to your computer and use it in GitHub Desktop.
Python question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
c = 0 # counter | |
def inc(): | |
global c | |
c = c + 1 | |
threads = list() | |
for index in range(4): | |
thr_id = threading.Thread(target=inc) | |
threads.append(thr_id) | |
for t in threads: | |
t.start() | |
print(c) | |
for t in threads: | |
t.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment