Re: translating "create Semaphore" to Linux



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:)

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. Main reason is that the socket-bind happens somewhere in
medusa or <someotherhttpsserverframeworkiuse>; so to use it as a
semaphore I would have to dig there. I am not totally sure what
trickery on socket is played down there; and I prefer to stay as far
away as possible from that area.

Harald


.



Relevant Pages

  • Re: some issue w.r.t. pthread_cond_signal( )
    ... semaphore and then you can keep the waiting and signalling like you ... First, there appears to be no real application shared data that serves obviously as a proper predicate, and my previous hurried answer focused too narrowly on repairing the incorrect predicate management around your condition variable -- I failed to observe that you didn't actually have a predicate. ... Except while each child sends data to its own external socket, you're using a single global message queue for the master to tell each child what data to send; and the master has already waited to read the input data for each connection. ...
    (comp.programming.threads)
  • How to test blocking calls (e.g. Sockets)
    ... Instantiate a Semaphore. ... Forking a process containing the "socket acceptance" ... newSpServerSocket were method vars, but were promoted it to instvars ... serverSocket:= ServerSocket2 port: 9999. ...
    (comp.lang.smalltalk.dolphin)
  • Re: How to test blocking calls (e.g. Sockets)
    ... Instantiate a Semaphore. ... Create a binded ServerSocket2. ... Forking a process containing the "socket acceptance" ... self assert: newSpServerSocket notNil. ...
    (comp.lang.smalltalk.dolphin)
  • [WinSock] WaitForMultipleObjects problems
    ... One accept the connection, another read/write/close, another ... Modules have a semaphore to know when a message arrived from another ... But if I don't use it WaitForMultipleObjects always quits as when there is ... activity on socket. ...
    (microsoft.public.win32.programmer.networks)
  • Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation
    ... > a mutex was a sensible implementation tradeoff. ... are really counting semaphores, ... >> acceptable patch that introduces a separate data structure. ... > general semaphore, because a mutex has stronger invariants. ...
    (Linux-Kernel)