Skip to content

Instantly share code, notes, and snippets.

@jfacorro
Created November 17, 2014 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfacorro/f864b977465121a46a6e to your computer and use it in GitHub Desktop.
Save jfacorro/f864b977465121a46a6e to your computer and use it in GitHub Desktop.
Check atomic operations on Python
import threading
import time
import random
a = []
def add(x):
for i in range(100):
print x
print len(a)
a.append(x)
print len(a)
def run(n):
for x in range(n):
t = threading.Thread(target = add, args = ([x]))
# t.daemon = True
t.start()
run(300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment