is +=1 thread safe
AlFire
spamgrinder.trylater at ggmail.com
Sun May 4 00:18:47 EDT 2008
Alexander Schmolck wrote:
> AlFire <spamgrinder.trylater at ggmail.com> writes:
>
>>> The threading module already has a function to return the number of Thread
>>> objects currently alive.
>> I have threads within threads - so it does not suit me :-(.
>
> How about using a scalar numpy array? They are mutable, so I assume that x +=
> 1 should be atomic.
>
I ended up with following:
counter=[] counter=0
counter.append(None) counter+=1
counter.pop() counter-=1
len(counter) counter
A.
More information about the Python-list
mailing list