On Tuesday 27 June 2006 20:58, you wrote: > On 27/06/2006, at 15:03, Tzahi Fadida wrote: > > I am looking for an answer on python threads lock behaviour. > > So far, i have not managed to get an answer on #python, > > whatsup,#twisted,google... > > You probably need to revise your questions.
Would like to say why? > > > If i have many threads running and there is a resource all want > > to posses using a lock, i.e., lock.acquire(). > > one obviously is going to posses the lock. > > My question is, when it is released using lock.release() which of > > the threads > > is going to acquire the lock? is it a random process or > > a FIFO order. I am trying to understand if starvation is possible > > in this particular instance. > > I think its undefined. > > > My other question, is what is more efficient: > > using locks, conditions, events, queues. i.e. i am building > > a server and i want to avoid unneccessary polling operations. > > The question is too general to get any useful answer. Sorry, but i don't think you are correct. For example, Event uses notifyAll while Condition uses notify etc... there is a difference, however there are other considerations like robustness etc... I am looking for an answer from someone who have experience with these. > > Basically, avoid threads if you can - its hard to program and even > harder to test. It also does not scale well with Python because of > the GIL, unlike C, most of the time all your threads share the same CPU. Basically what you are saying, python is a lame language since you cannot use threads with it. I disagree of course. Sharing CPU is the least of my problems. If you want to cause python to work on multiple processors you can use C extensions to release GIL or even more simple, just fork() or spaw processess as the number of processors you have and thread away in those processes and communicate using shared memory or twisted etc... > > I don't have any idea what is the server you are writing, but I would > generally try to use twisted, which will save you lot of time. I am using twisted. Twisted also uses and recommends to use threads for computations. Since twisted uses non-blocking I/O and uses only one centralised event loop, you must use threads for computations, less you will create a bottelneck for new connections and data transfers. > > > Best Regards, > > Nir Soffer -- Regards, Tzahi. -- Tzahi Fadida Blog: http://tzahi.blogsite.org | Home Site: http://tzahi.webhop.info WARNING TO SPAMMERS: see at http://members.lycos.co.uk/my2nis/spamwarning.html