"prints different results on different runs on windows import threadingtime count def adder()global count count count time sleep( count count update shared name in global scope threads share object memory and global names threads [for in range( )thread threading thread(target=adderargs=()thread start(threads append(threadfor thread in threadsthread join(print(counthere threads are spawned to update the same global scope variable twice (with sleep between updates to better interleave their operationswhen run on windows with python different runs produce different resultsc:\pp \system\threadsthread-add-random py :\pp \system\threadsthread-add-random py :\pp \system\threadsthread-add-random py :\pp \system\threadsthread-add-random py this happens because threads overlap arbitrarily in timestatementseven the simple assignment statements like those hereare not guaranteed to run to completion by themselves (that isthey are not atomicas one thread updates the globalit may be using the partial result of another thread' work in progress the net effect is this seemingly random behavior to make this script work correctlywe need to again use thread locks to synchronize the updates--when example - is runit always prints as expected example - pp \system\threads\thread-add-synch py "prints each timebecause shared resource access synchronizedimport threadingtime count def adder(addlock)shared lock object passed in threads