note 118174 added to function.sem-get
| From: | kakkau at grr dot la | Date: | Tue, 20 Oct 2015 21:35:51 +0000 |
| Subject: | note 118174 added to function.sem-get | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203989@lists.php.net to get a copy of this message | ||
For those that encounter strange behavior in using sem_acquire() on resources generated by
sem_get(). Have a look at sem_get()'s 4th parameter auto_release. It allows multiple
acquisitions through reassignments to resource variables.
./multi.acquire.php
<?php
class Sem {
private $key = null;
private $res = null;
public function __construct() {
$this->key = ftok(".",".");
$this->set_res();
$this->acquire();
}
public function set_res() {
// 4th parameter auto_released is 1 by default
$this->res = sem_get($this->key, 1, 0600, 1);
}
public function acquire() {
echo "acquired='".sem_acquire($this->res,true)."'\n";
}
}
$s = new Sem();
$s->set_res();
$s->acquire();
?>
$ php multi.acquire.php
acquired='1'
acquired='1'
To avoid reacquiring by default set sem_get()'s parameter auto_release to 0 or check if your
resource variable is already set, e.g. by using is_null().
----
Server IP: 72.52.91.14
Probable Submitter: 87.178.177.163
----
Manual Page -- http://php.net/manual/en/function.sem-get.php
Edit -- https://master.php.net/note/edit/118174
Del: integrated -- https://master.php.net/note/delete/118174/integrated
Del: useless -- https://master.php.net/note/delete/118174/useless
Del: bad code -- https://master.php.net/note/delete/118174/bad+code
Del: spam -- https://master.php.net/note/delete/118174/spam
Del: non-english -- https://master.php.net/note/delete/118174/non-english
Del: in docs -- https://master.php.net/note/delete/118174/in+docs
Del: other reasons-- https://master.php.net/note/delete/118174
Reject -- https://master.php.net/note/reject/118174
Search -- https://master.php.net/manage/user-notes.php