note 107487 added to function.sem-acquire
| From: | Pinky | Date: | Mon, 13 Feb 2012 08:29:18 +0000 |
| Subject: | note 107487 added to function.sem-acquire | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186098@lists.php.net to get a copy of this message | ||
sem_acquire() is blocking, meaning that subsequent calls with the same semaphore will block
indefinitely until the semaphore is released. This ensures serialization, but it is not very
practical if all you want to do is check if you should proceed or not. Unfortunately, PHP does not
yet support any method of querying the state of a semaphore in a non-blocking manner.
It may seem possible to put together such a mechanism by hand, using shared memory (shm_ functions).
However, be warned that it is not trivial and ultimately non-productive. You cannot, for example,
simply pick a shared mem var, store the semaphore key and query it. Such an operation would be
non-transactional and non-atomic ie. it is possible for two or more parallel processes to manage to
read "not locked" from the shared mem var before one of them manages to mark it
"locked". You would have to use a (blocking) semaphore to serialize access to the shared
mem var, thus recreating the very problem you are trying to solve.
In other words, if non-blocking queries are crucial to you, you need to either request that this
issue be solved by the PHP designers, or pick another mechanism to do your locking, one that already
has this feature.
----
Server IP: 69.147.83.197
Probable Submitter: 194.88.148.6
----
Manual Page -- http://www.php.net/manual/en/function.sem-acquire.php
Edit -- https://master.php.net/note/edit/107487
Del: integrated -- https://master.php.net/note/delete/107487/integrated
Del: useless -- https://master.php.net/note/delete/107487/useless
Del: bad code -- https://master.php.net/note/delete/107487/bad+code
Del: spam -- https://master.php.net/note/delete/107487/spam
Del: non-english -- https://master.php.net/note/delete/107487/non-english
Del: in docs -- https://master.php.net/note/delete/107487/in+docs
Del: other reasons-- https://master.php.net/note/delete/107487
Reject -- https://master.php.net/note/reject/107487
Search -- https://master.php.net/manage/user-notes.php