Simple thread-safe counter?
Michael Hudson
mwh at python.net
Tue Apr 5 05:42:18 EDT 2005
Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> Tim Peters <tim.peters at gmail.com> writes:
> > The GIL is your friend here:
> >
> > import itertools
> > f = itertools.count().next
>
> Thanks, I was hoping something like this would work but was not sure I
> could rely on it.
>
> > A similar thing can be done with xrange. But either way sucks if you
> > call it often enough to exceed the size of a Python short int
> > (platform C long). The obvious way with an explicit mutex doesn't
> > have that problem.
>
> Xrange, of course :). I don't need to exceed the size of a short int,
> so either of these should work fine. I wonder what measures the Pypy
> implementers will take (if any) to make sure these things keep
> working, but for now I won't worry about it.
Well, for now we don't support threads. Easy!
Cheers,
mwh
(no, really, this is for the future)
--
Two things I learned for sure during a particularly intense acid
trip in my own lost youth: (1) everything is a trivial special case
of something else; and, (2) death is a bunch of blue spheres.
-- Tim Peters, 1 May 1998
More information about the Python-list
mailing list