Skip to content

Instantly share code, notes, and snippets.

@ppergame
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppergame/10751696 to your computer and use it in GitHub Desktop.
Save ppergame/10751696 to your computer and use it in GitHub Desktop.
import time
import os
import sys
from __pypy__.thread import atomic, last_abort_info
from threading import Thread
N = 3
def conflict(name, x):
# x = []
for i in range(N):
with atomic:
time.sleep(0.5)
x.append(name)
# time.sleep(0.0001)
# if name == 'a':
# while 1: pass
def main():
x = []
a = Thread(target=conflict, args=("a", x))
b = Thread(target=conflict, args=("b", x))
a.start()
b.start()
a.join()
b.join()
# print 'x:', "".join(map(str, x[:N]))
# print 'x:', "".join(map(str, x[N:]))
print x
print x[:N] == x[N:]
sys.stdout.flush()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment