Skip to content

Instantly share code, notes, and snippets.

@TakesxiSximada
Created January 30, 2016 09:59
Show Gist options
  • Save TakesxiSximada/1ec4e3368af8cb6a983b to your computer and use it in GitHub Desktop.
Save TakesxiSximada/1ec4e3368af8cb6a983b to your computer and use it in GitHub Desktop.
スレッドセーフじゃない例
#! /usr/bin/env python
import time
from threading import Thread
count = 0
class CountUpThread(Thread):
def run(self):
global count
for ii in range(1000):
value = count
time.sleep(0.001)
value += 1
count = value
children = [CountUpThread() for ii in range(100)]
for child in children:
child.start()
for child in children:
child.join()
print(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment