Dennis Kellly
07/02/2008 8:25 AM
post9904
|
The neutrino (I assume posix?) "feature" that a named semaphores outlives the process which created it, seems to make
their use complicated.
For example, if a second instance opens a named semaphore created by a previous instance, the state of the semaphore
cannot be trusted - i.e. the first process may have left the semaphore with a count of zero due to a trap OR it may be
holding the semaphore intentionally - SO the second process cannot reliably "wait" AND neither can it "unlink" it since
it may be valid!
After reading the following, I thought the creator instance could issue sem_unlink() which would be DELAYED until all
instances had closed the semaphore ... BUT nto does not work this way... in fact sem_unlink() removes the named
semaphore EVEN WHILE the creator still holds it open i.e. there is no "delayed" unlink in nto!
http://www.opengroup.org/onlinepubs/007908799/xsh/sem_unlink.html
"The sem_unlink() function removes the semaphore named by the string name. If the semaphore named by name is currently
referenced by other processes, then sem_unlink() has no effect on the state of the semaphore. If one or more processes
have the semaphore open when sem_unlink() is called, destruction of the semaphore is postponed until all references to
the semaphore have been destroyed by calls to sem_close(), _exit(), or exec. Calls to sem_open() to re-create or re-
connect to the semaphore refer to a new semaphore after sem_unlink() is called. The sem_unlink() call does not block
until all references have been destroyed; it returns immediately."
Suggestions on how a subsequent instance may reliably use an existing named semaphore would be appreciated.
Dennis
|
|
|