''' threads2.py Jeff Ondich, 15 November 2010 Same as threads.py, but this time only prints a message if there's an apparent race condition. Note that the print statement itself could potentially get interrupted. How does that affect things? ''' from threading import * class FightingThread(Thread): def __init__(self, symbol): Thread.__init__(self) self.symbol = symbol def run(self): for j in range(100000): for k in range(len(gSharedList)): gSharedList[k] = self.symbol if gSharedList != [self.symbol] * len(gSharedList): print self.symbol, ':', gSharedList gSharedList = ['x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'] threadA = FightingThread('a') threadB = FightingThread('b') threadA.start() threadB.start()