Alex Martelli wrote:
> Wrong, alas: each assignment *could* cause the dictionary's internal
> structures to be reorganized (rehashed) and impact another assignment
> (or even 'get'-access).

(been thinking about this further...)

Dictionary get/set operations *must* be atomic, because Python makes
extensive internal use of dicts.

Consider two threads A and B, which are independent except for the fact
that they reside in the same module.

def thread_A() :
    global foo
    foo = 1

def thread_B() :
    global bar
    bar = 2

These threads create entries in the same module's dict, and they *might*
execute at the same time. Requiring a lock in this case is very
non-intuitive, and my conclusion is that dict get/set operations are
indeed atomic (thanks to the GIL).

Regards
Sreeram

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to