atomic increment

Frank Millman frank at chagford.com
Wed Aug 27 07:09:52 CEST 2008


On Aug 26, 5:56 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
> Alexandru  Mosoi wrote:
> > how can i do an atomic read+increment? something like
>
> > with lock:
> >    old = atomic_int
> >    atomic_int += 1
>
> > but in one operation
>
> As above - the lock (under the assumption that it is actually a
> threading.Lock) will ensure that.
>
> Diez

Just out of interest, would the following, without a lock, be safe?

old, atomic_int = atomic_int, atomic_int+1

Frank Millman



More information about the Python-list mailing list