Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - sem_unlink() behavior: (2 Items)
   
sem_unlink() behavior  
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
Re: sem_unlink() behavior  
> 
> 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!
> 


If they work like shared memory after an unlink, it still exists but it's not accessible.  You cannot see it anymore ( 
for example with ls ) but it's still  there.  I assume named semaphore behave the same.