Threading
Thomas Jensen
thomasNO at SPAM.obscure.dk
Wed Nov 14 16:45:21 EST 2001
"Tim Peters" <tim at zope.com> wrote in
news:mailman.1005755427.14226.python-list at python.org:
> In this case, being sure about the answer is much easier than being
> sure about the question <wink>. If you run *any* sequence of dict
> operations without benefit of locks (get, set, update, clear,
> whatever), the outcome will be "sequentially consistent", meaning
> the outcome will be the same as if you had run the dict operations
> one at a time with benefit of exclusion, for *some* intervleaving
> of dict operations across threads: each dict operation is atomic
> (e.g., once a dict.update() starts, it completes before another
> thread is allowed to run). In particular, if there are no
> mutations going on, any number of threads can read simultaneously
> without locks without surprises.
That's very interesting, I'm usually quite paranoid about wrapping such
stuff in locks.
Is there any "rule-of-thumb" (or doc) regarding which operations are
atomic, for example is the following safe:
thread 1:
mylist.reverse()
thread 2:
for item in mylist:
...
(silly example perhaps)
--
Best Regards
Thomas Jensen
More information about the Python-list
mailing list