On Tue, 2 Jan 2007 08:35:10 +0100
"Wojciech Malota" <[EMAIL PROTECTED]> wrote:

> It's impossible to correct remove semaphores with sem_remove function
> when I use them to provide execution of concurrent processes.
> When the last process releases the semaphore I should be able to remove
> it. But I don't know if another process haven't acquired the semaphore.
> For safety reasons I don't remove released semaphores from system.
> Now, If I get 128 semaphores and I execute sem_get one more time I will
> get warning.
> So, I can't remove semaphores (because I don't know if another process
> is using it) and I can't get next semaphore.
> I will try to tell about my sugestion.
> 
> I assume that I have a function my_sem_remove($sem_id):
> 
> function my_sem_remove($id) {
>   if(Semaphore $id isn't acquired and its FIFO is empty)
>     sem_remove($id);
<snip>
> It's the best solution, without danger of operating on not existing
> semaphores. Also, unused semaphores are automaticcally removed. The
> problem is, that functions my_sem_acquire and my_sem_release can't be
> witten in PHP so it must be done in C inside source of PHP.

I don't understand. If your "FIFO" is some kind of refcount that won't
work because the refcount would not be shared by multiple separate
PHP processes. You would have to put the refcount in shared memory
and even then there's no guarantee that the semaphore will be cleaned
up properly because any exit routine will not run if the application
is killed, crashes, aborts, etc.

The left-over SysV semaphore problem is notoriously impossible. There
basically is no solution other than to simply use something other than
SysV semaphores such as process-shared POSIX semaphores (not as portable
as SysV semphores).

Mike

-- 
Michael B Allen
PHP Active Directory SSO
http://www.ioplex.com/

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to