Skip to content

Instantly share code, notes, and snippets.

@inv2004
Last active October 5, 2022 13:34
Show Gist options
  • Save inv2004/11e2986b23042c009a48272b475acda2 to your computer and use it in GitHub Desktop.
Save inv2004/11e2986b23042c009a48272b475acda2 to your computer and use it in GitHub Desktop.
Python question
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