why the following python program does not face any concurrency problems without synchronize mechanism?

smith jack thinke365 at gmail.com
Sat Jul 9 16:45:30 EDT 2011


from threading import Thread

def calc(start, end):
    total = 0;
    for i in range(start, end + 1):
        total += i;
    print '----------------------result:', total
    return total

t = Thread(target=calc, args=(1,100))
t.start()

I have run this program for many times,and the result is always 5050,
if there is any concurrency problem, the result should not be 5050,
which is never met, anyhow
I mean this program should get the wrong answer at some times, but
this never happens, why?
can concurrency without synchronize mechanism always get the right answer?
any special case in python programming?



More information about the Python-list mailing list