Skip to content

Instantly share code, notes, and snippets.

@akshar-raaj
Created September 8, 2013 05:54
Show Gist options
  • Save akshar-raaj/6482219 to your computer and use it in GitHub Desktop.
Save akshar-raaj/6482219 to your computer and use it in GitHub Desktop.
A simple program demonstrating race condition
import threading
#define a global variable
some_var = 0
class IncrementThread(threading.Thread):
def run(self):
#we want to read a global variable
#and then increment it
global some_var
b = some_var
print "some_var in %s is %d" % (self.name, b)
some_var = b + 1
print "some_var in %s after increment is %d" % (self.name, some_var)
if __name__ == "__main__":
for i in range(10):
t = IncrementThread()
t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment