Re: [LAD] [somewhat OT] semaphores in python

From: Fons Adriaensen <fons@email-addr-hidden>
Date: Tue Aug 26 2008 - 23:01:18 EEST

On Tue, Aug 26, 2008 at 09:55:07PM +0200, Arnold Krille wrote:

> Am Dienstag, 26. August 2008 schrieb Fons Adriaensen:

> > Does anyone know of a counting semaphare class/module
> > in Python ? Given the lock provided by the built-in
> > thread module it seems impossible to implement this
> > (it does support multiple waiters which I don't need,
> > but definitely is not counting). This also means that
> > whatever is defined in the threading module can't be
> > what I want.
>
> Did you look at the threading module? Looks as if there a Semaphore() in
> there...

Did you look two lines above yours :-) :-) :-)

Yes, of course I did. It defines a Semaphore on top of
a Condition which is pure ugly hackery on top of a RLock.
Can't be correct, since AFAICS the primitives provided
by thread are not sufficient. Apart from the fact that
a sema requiring a few hundreds of lines of high-level
code can't be healthy.

The basic problem is that the lock provided by thread
is not counting: releasing it while it is not acquired
produces and error. Of course one could create a class
that contains a counter, but then the problem is to
atomically modify the counter and access the lock.
AFAICS, for this reason, whatever happens in threading
can't be correct, or at least not pre-emption and SMP
safe.

Ciao,

-- 
FA
Laboratorio di Acustica ed Elettroacustica
Parma, Italia
O tu, che porte, correndo si ?
E guerra e morte !
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Wed Aug 27 00:15:05 2008

This archive was generated by hypermail 2.1.8 : Wed Aug 27 2008 - 00:15:06 EEST