Question regarding thread atomicity
Paul Rubin
http
Mon Nov 24 13:45:43 EST 2003
Jon Ribbens <jon+usenet at unequivocal.co.uk> writes:
> 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 :-(
I have to agree, it looks like a pretty bad bug. The most natural way
I can think of to fix it is to add something like references to the
bytecode interpreter, so that
7 LOAD_ATTR 2 (bar)
10 LOAD_CONST 1 (1)
13 INPLACE_ADD
14 ROT_TWO
15 STORE_ATTR 2 (bar)
would become something like
LOAD_REF 2 (bar) # load a pointer to bar's location
LOAD_CONST 1
INPLACE_ADD_REF
However, apparently there's some implementation reasons to not want to
do it that way.
More information about the Python-list
mailing list