Created
November 17, 2014 05:58
-
-
Save jfacorro/f864b977465121a46a6e to your computer and use it in GitHub Desktop.
Check atomic operations on Python
This file contains hidden or 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 | |
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