thread-safe swap

Aahz aahz at pythoncraft.com
Wed Mar 27 18:44:59 EST 2002


In article <833cyl3gfe.fsf_-_ at panacea.canonical.org>,
Kragen Sitaker  <kragen at pobox.com> wrote:
>
>Someone recommended using the idiom
>
>    spam, eggs = eggs, spam
>
>to get a thread-safe swap.  Does this really work?

Not really.  IIRC, there are some specific circumstances where it does
work, but better to protect it with an RLock().  OTOH, it's safe if spam
and eggs are both local.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?



More information about the Python-list mailing list