Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9115

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

Date 2011-07-10 04:45 +0800
Subject why the following python program does not face any concurrency problems without synchronize mechanism?
From smith jack <thinke365@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.803.1310244333.1164.python-list@python.org> (permalink)

Show all headers | View raw


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?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

why the following python program does not face any concurrency problems without synchronize mechanism? smith jack <thinke365@gmail.com> - 2011-07-10 04:45 +0800
  Re: why the following python program does not face any concurrency problems without synchronize mechanism? TheSaint <nobody@nowhere.net.no> - 2011-07-10 22:50 +0800

csiph-web