atomic operations in presence of multithreading

Dave Brueck dave at pythonapocrypha.com
Tue Jul 27 14:21:49 EDT 2004


Glenn Kasten wrote:

> I am wondering which operations in Python
> are guaranteed to be atomic in the presence
> of multi-threading. In particular, are assignment
> and reading of a dictionary entry atomic?
[snip]
> I just want to make sure
> that the dictionary internal data structures can't
> become corrupted by multiple writers / readers.
[snip]
> Python operations are atomic, and which are not.
> I was unable to find this in the language reference,
> but please direct me to the correct location
> if I missed it.

It's probably not spelled out anywhere, but the "global interpreter 
lock" entry and the Glossary and the first few paragraphs of section 8.1 
of the documentation ("Thread State and the Global Interpreter Lock") 
give you the gist of it.

Basically: multiple threads can't corrupt the interpreter's internals 
(but a buggy C extension could).

-Dave



More information about the Python-list mailing list