Pierre Barbier de Reuille <[EMAIL PROTECTED]> wrote:
> 
> Ville Vainio a écrit :
> >>>>>>"Bastian" == Bastian Hammer <[EMAIL PROTECTED]> writes:
> > 
> > 
> >     Bastian> Now I have to make sure, that both threads are
> >     Bastian> synchronal, 1 thread edits something and the other is
> >     Bastian> blocked until the first thread is ready.
> > 
> >     Bastian> Isn´t it a good idea to do this with a semaphore?
> > 
> > Semaphore will do, but this is a classical use case for
> > threading.Lock.
> > 
> > There should be lots of stuff regarding locks (or more googleably,
> > "mutexes") on the net.
> > 
> 
> I don't agree. Mutexes (or locks) are best suited for critical sections 
> (ie. sections that cannot be run by many thread at the same time). The 
> kind of synchonisation Bastian want is not really semaphore either but 
> more event. This python "Event" object is described in the section 7.5.5 
> of the documentation of Python 2.3. There is no example, but I think 
> Event are quite strait forward : you creates it, then some thread block, 
> waiting the event to occure while some other thread execute until it set 
> the event, allowing the blocked thread to go on its own execution :)

You can agree or disagree as much as you want.  Fundamentally, they are
all equivalent.

The only thing that makes mutex 'special' is that one can have an
optional 'call this function with this argument when it gets the lock',
but that can be implemented with a standard Lock, Condition, Event,
Semaphore, etc.


 - Josiah

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

Reply via email to