multithreading and shared dictionary

placid Bulkan at gmail.com
Sat Jul 8 03:55:34 EDT 2006


Alex Martelli wrote:
> Istvan Albert <istvan.albert at gmail.com> wrote:
>
> > Stéphane Ninin wrote:
> >
> > > Is a lock required in such a case ?
> >
> > I believe that assignment is atomic and would not need a lock.
>
> Wrong, alas: each assignment *could* cause the dictionary's internal
> structures to be reorganized (rehashed) and impact another assignment
> (or even 'get'-access).


Oh yeah you are correct, i forgot about possible rehashing after
assignment operation, so to that means you do need to use a lock to
restrict only one thread at time from accessing the dictionary. Again i
recommend using a Queue to do this. If you need help with usage of
Queue object first see
http://www.google.com/notebook/public/14017391689116447001/BDUsxIgoQkcSO3bQh
or contact me

-Cheers




More information about the Python-list mailing list