Created
April 19, 2012 22:13
-
-
Save dcolish/2424566 to your computer and use it in GitHub Desktop.
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 | |
| 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