shared info: safety and performance questions

Tim Peters tim_one at email.msn.com
Sun May 2 19:29:20 EDT 1999


[nathan at islanddata.com]
> ...
> I don't want to deal with semaphores/mutexes/etc. unless necessary.
> What python commands are considered atomic and threadsafe?  I would
> especially be interested in append() and del being safe, as well as
> mutation of lists and dictionaries through reassignment.

See the new FAQ entry:

    4.88. What kinds of global value mutation are thread-safe?

at (for the next week <wink>):

    http://grail.cnri.reston.va.us/cgi-bin/faqw.py?req=recent&days=7

> Next, performance.  Functions in different threads and idlefuncs need
> to share data.  One func might need list a, another might need dict b,
> another may need tuple c, and another might need a and c but not b.
> Would it be faster to send each mutable variable where it belongs, or
> stuff them all in a giant dictionary which gets passed to each shared
> function regardless of its need, which looks up only the appropriate
> keys?

Those are difficult design decisions that have less to do with performance
than keeping things working under modification.  No easy answers.  Note that
(within reason) giant dicts are no slower than tiny dicts, so if you want to
organize your shared data that way there's not a performance argument
against it.

the-best-way-to-share-data-is-not-to-ly y'rs  - tim






More information about the Python-list mailing list