What's an "atomic" operation (in a threaded context)?

Paul Moore pf_moore at yahoo.co.uk
Thu Nov 13 00:19:32 CET 2003


Peter Hansen <peter at engcorp.com> writes:

> In a nutshell, your "single bytecode operation" theory is correct,
> and each of the above lines represents a single bytecode.  Therefore
> the only line which matters is STORE_SUBSCR (the actual assignment)
> and it is atomic, so you can have any number of threads running but
> no matter how they try, they won't be able to interrupt each other's
> STORE_SUBSCR operations and the dictionary will stay in a consistent
> state.

Thanks. I think I'd got bogged down in C-level thinking ("STORE_SUBSCR
can reallocate the dictionary, so it's address changes, so doesn't
that mean another thread might have loaded its address and then it
moves...")

> Much or most of the time, basic operation such as this on the standard
> mutable primitive types (i.e. lists, dictionaries) are atomic/safe for
> use in the way you wish to use them, without needing locks.

That's good to know. And the trick of using dis to analyze it will
help as well.

Thanks for the explanation,
Paul
-- 
This signature intentionally left blank




More information about the Python-list mailing list