note 76793 added to function.sem-get

From: Date: Tue, 31 Jul 2007 03:55:35 +0000
Subject: note 76793 added to function.sem-get
Groups: php.notes 
Request: Send a blank email to php-notes+get-129064@lists.php.net to get a copy of this message
in regards to the last post, it looks like there is a mistake. well, understandably, the documentation isnt quite clear on a point the post uses to rationalize its claim, allow me to explain. the purpose of a semaphore is to manage access to a shared resource, so natrually it follows that if multiple attempts to access the same semaphore arent blocking (when expected to), then the api simply isnt being used properly. the problem is that the documentation does not stipulate what will happen if the max_acquire paramter is varied upon successive invocations of the sem_get method. so setting it to 100, then to 1 on 2 successive calls will have an undefined behavior. if the value is kept constant however (and set to 1 for the example), you will find, as i did that the second attempt to acquire the semaphore will block. NOTE: this does not work when using php -a here is the revised sample code: <?php $fp1 = sem_get(fileinode('commonResource'), 1); sem_acquire($fp1); echo 'got mutex' . PHP_EOL; $fp2 = sem_get(fileinode('commonResource'), 1); sem_acquire($fp2); echo 'got mutex again' . PHP_EOL; ?> note there are 2 references; $fp1 and $fp2 and you will not see the second message because the script will block forever. ---- Server IP: 69.147.83.197 Probable Submitter: 74.128.143.178 ---- Manual Page -- http://www.php.net/manual/en/function.sem-get.php Edit -- https://master.php.net/note/edit/76793 Del: integrated -- https://master.php.net/note/delete/76793/integrated Del: useless -- https://master.php.net/note/delete/76793/useless Del: bad code -- https://master.php.net/note/delete/76793/bad+code Del: spam -- https://master.php.net/note/delete/76793/spam Del: non-english -- https://master.php.net/note/delete/76793/non-english Del: in docs -- https://master.php.net/note/delete/76793/in+docs Del: other reasons-- https://master.php.net/note/delete/76793 Reject -- https://master.php.net/note/reject/76793 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129064) next »