Question regarding thread atomicity

Jon Ribbens jon+usenet at unequivocal.co.uk
Mon Nov 24 13:30:33 EST 2003


In article <3FC24C35.E5742B6F at engcorp.com>, Peter Hansen wrote:
> The basic failure mode would be that two threads both retrieve
> the same current value for "bar" and add one to it "INPLACE", then 
> store it back again: the result is that although two attempts to
> add have been made, the value increases by only one.  Python won't
> crash, which is why this all depends on your definition of "thread-safe",
> but it likely won't do what you probably want it to do.

Ah. This violates my definition of "thread-safe" ;-) If it doesn't go
up by exactly one every time that line is executed, it isn't doing
what I want it to do. I guess I'll have to go and add a load of manual
locking :-(




More information about the Python-list mailing list