translating "create Semaphore" to Linux

Tim Golden mail at timgolden.me.uk
Fri Aug 29 09:03:43 EDT 2008


GHUM wrote:
> Tim,
> 
>> ... why use a Semaphore rather than a Mutex?
> 
> as much as I understood the documentation at MSDN
> 
> http://msdn.microsoft.com/en-us/library/ms686927(VS.85).aspx
> http://msdn.microsoft.com/en-us/library/ms686946(VS.85).aspx
> 
> a mutex seems to be nothing else than a special case of a semaphore?
> That is, a semaphore can be created to allow  MAX_SEM_COUNT concurrent
> runners, and MUTEX defaults to one and only one ...
> 
> The other api-spells are identical, like wait_for_xxxx...; so propably
> I stumbled on the working Semaphore Code before, or in some ancient
> win32 wrapper createMutex was not documented or something in that
> aspect:)

I think it hardly matters except that someone (like me :) )
coming to your code who's familiar with the uses of mutex
and semaphore elsewhere -- they're not Microsoft inventions
as I'm sure you realise -- will be a little stumped by the
fact that a mutex is pretty much the canonical recipe for
allowing only one instance of an app, yet you're using a
semaphore which can be used for slightly different
purposes. I'd be wondering whether you had some more
sophisticated model in mind which I was unable to fathom...

> 
>> Or why notsimply use the bound socket as its own mutex? I know
>> Windows won't allow you to rebind the same socket to the
>> same addr/port in two different processes (unless perhaps
>> you play some trickery with the socket options).
> 
> My experience was that this is correct for certain values of "allow"
> and "trickery". Sometimes the binding seems to get allowed but does
> not work. 

Fair enough.

TJG



More information about the Python-list mailing list