How smart are Semaphore Objects?

Grant Edwards grante at visi.com
Tue Oct 30 16:52:23 CET 2001


In article <32cedc66.0110300638.4a51129 at posting.google.com>, Matthew D. Wood wrote:
> Ype Kingma <ykingma at accessforall.nl> wrote in message 
> 
>> A Semaphore can be released from an other thread.
> 
> That sucks.

Says you...

>> It can be better for performance to release a Semaphore from another thread.
>> I would consider this as a candidate for style improvement, though.
> 
> I don't understand.  Why would it be better for a non-owning thread to
> release a Semaphore?

I just recently wrote an application (not in Python) where
common resournces (a pool of serial ports) is shared by two
distinct groups of threads.  Each group of threads impliments a
more-or-less independant function, but only one group can have
ownership of the serial port.

In each group of threads, there is one thread that is accepting
incoming network connections.  That thread is responsible for
acquiring the serial port.  Once the connection is set up,
there is a different thread for each active connection that
handles traffic.  The traffic handling thread is responsible
for shutting down the connection and releasing the serial port.

Perhaps it's a flaw in my overall system design, but it was
simpler by far to have one thread acquire the resource and a
different one release it.

-- 
Grant Edwards                   grante             Yow!  I'm using my X-RAY
                                  at               VISION to obtain a rare
                               visi.com            glimpse of the INNER
                                                   WORKINGS of this POTATO!!



More information about the Python-list mailing list