[Zope-dev] ThreadSafeCounter 0.0.1 released

Steve Alexander steve@cat-box.net
Sun, 11 Feb 2001 16:10:09 +0000


Chris Withers wrote:

> "Morten W. Petersen" wrote:
> 
>> There's a new product available, which enables unique ids in a given context,
>> take a look at <url:http://www.zope.org/Members/morphex/ThreadSafeCounter>.
> 
> 
> So would a counter such as:
> 
> class PersistentCounter(Persistent):
> 
>     # create the counter
>     def __init__(self, value=0):
>         self._value = value
> 
>     # get the value of the counter without incrementing
>     def getValue(self):
>         return self._value
> 
>     # increment the counter when called, and return the new value
>     def __call__(self, number=1):
>         self._value = self._value + number
>         return self._value
> 
> ...not be thread safe?
> 
> If not, can anyone explain how it could be made thread safe?

That's not the issue. Morten's product stores the counter's
value in a file on the filesystem, and so it doesn't cause the
Data.fs to grow.

The trade-off is that it doesn't participate in history or undo.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net