From: thornza at yahoo dot com Operating system: Linux PHP version: 5.2.5 PHP Bug Type: Feature/Change Request Bug description: sem_remove does not seem to take SYSVSEM_USAGE into account
Description: ------------ Two processes - processA and processB - are using a semaphore. processA sem_get()s the semaphore. (the semaphore is created) processB sem_get()s the semaphore. (the semaphore is already created, so the semaphore id is just returned) processA sem_acquire()s the semaphore and begins to work in the critical section. processB sem_acquire()s the semaphore and BLOCKS. processA finishes in it's critical section and sem_release()s. processA sem_remove()s the semaphore ***THE SEMAPHORE HAS NOW BEEN REMOVED - I think that this part is incorrect**** processB now is NOT able to continue as the semaphore has been removed. sem_remove() should take the SYSVSEM_USAGE (see sysvsem.c) count into consideration when it is called. Only if this count is == 1 should the semaphore be removed. This will allow the last process that is using the semaphore to remove it from the system. Reproduce code: --------------- <?php //Note - run this script from two different clients at the same time. //add your own critical section code and output logging. $semKey = 1234; $semHandle = sem_get($semKey, 1, 0666, FALSE); sem_acquire($semHandle); //critical section //do something useful here sem_release($semHandle); sem_remove($semHandle); ?> Expected result: ---------------- processA and processB both able to work in their critical sections without error. Actual result: -------------- Log messages such as the following are generated: [13-Feb-2008 14:36:30] PHP Warning: sem_acquire() [<a href='function.sem-acquire'>function.sem-acquire</a>]: failed to acquire key 0x2b72: Invalid argument in /opt/MarkDW/Exec/Form.php on line 1282 -- Edit bug report at http://bugs.php.net/?id=44109&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=44109&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44109&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44109&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44109&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44109&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44109&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44109&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44109&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44109&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44109&r=support Expected behavior: http://bugs.php.net/fix.php?id=44109&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44109&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44109&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44109&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=44109&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=44109&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44109&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44109&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44109&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44109&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44109&r=mysqlcfg