Skip to content

Instantly share code, notes, and snippets.

@dcolish
Created April 19, 2012 22:13
Show Gist options
  • Select an option

  • Save dcolish/2424566 to your computer and use it in GitHub Desktop.

Select an option

Save dcolish/2424566 to your computer and use it in GitHub Desktop.
import threading
import time
import random
import atomic
foo = 0
class Worker(threading.Thread):
def run(self):
global foo
time.sleep(random.random())
foo += 1 # atomic.int_add(foo, 1)
print foo
def main():
workers = {}
for _ in range(10):
thread = Worker()
thread.start()
workers[thread.name] = thread
for _, worker in workers.items():
worker.join()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment