Re: multithreading and shared dictionary

2006-07-08 Thread Aahz
In article <[EMAIL PROTECTED]>, Istvan Albert <[EMAIL PROTECTED]> wrote: >Marc 'BlackJack' Rintsch wrote: >> >> It's not in Jython nor IronPython and maybe not forever in >> CPython. > >Whether or not a feature is present in Jython or IronPython does not >seem relevant, after all these languages em

Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
K.S.Sreeram <[EMAIL PROTECTED]> wrote: ... > Alex Martelli wrote: > > Well then, feel free to code under such assumptions (as long as you're > > not working on any project in which I have any say:-) > > Hey, I would *never* write code which depends on such intricate > implementation details! No

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Alex Martelli wrote: > Well then, feel free to code under such assumptions (as long as you're > not working on any project in which I have any say:-) Hey, I would *never* write code which depends on such intricate implementation details! Nonetheless, its good to *know* whats going on inside. As th

Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
Istvan Albert <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch wrote: > > > It's not in Jython nor IronPython and maybe not forever in > > CPython. > > Whether or not a feature is present in Jython or IronPython does not > seem relevant, after all these languages emulate Python, one could

Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
K.S.Sreeram <[EMAIL PROTECTED]> wrote: ... > 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

Re: multithreading and shared dictionary

2006-07-08 Thread Istvan Albert
Marc 'BlackJack' Rintsch wrote: > It's not in Jython nor IronPython and maybe not forever in > CPython. Whether or not a feature is present in Jython or IronPython does not seem relevant, after all these languages emulate Python, one could argue that it only means that this emulation is incomplet

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
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

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Marc 'BlackJack' Rintsch wrote: >>> Wrong, alas: each assignment *could* cause the dictionary's internal >>> structures to be reorganized (rehashed) and impact another assignment >>> (or even 'get'-access). >> but wont the GIL be locked when the rehash occurs? > > If there is a GIL then maybe yes.

Re: multithreading and shared dictionary

2006-07-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, K.S.Sreeram wrote: > 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). > > but wont the GIL be locked when the rehash occurs? If

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
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). but wont the GIL be locked when the rehash occurs? Regards Sreeram signature.asc Description: OpenPGP di

Re: multithreading and shared dictionary

2006-07-08 Thread placid
Alex Martelli wrote: > Istvan Albert <[EMAIL PROTECTED]> 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

Re: multithreading and shared dictionary

2006-07-07 Thread Alex Martelli
Istvan Albert <[EMAIL PROTECTED]> 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 a

Re: multithreading and shared dictionary

2006-07-07 Thread Istvan Albert
Stéphane Ninin wrote: > Is a lock required in such a case ? I believe that assignment is atomic and would not need a lock. yet most of the other dictionary use cases are not threadsafe. For example I suspect that you'd get an error if you were iterating through the dictionary while another threa

Re: multithreading and shared dictionary

2006-07-07 Thread placid
Stéphane Ninin wrote: > Hello, > > Probably a stupid question, but I am not a multithreading expert... > > I want to share a dictionary between several threads. > Actually, I will wrap the dictionary in a class > and want to protect the "sensitive accesses" with locks. > > The problem is I am not