PHP Doku:: Semaphor freigeben - function.sem-release.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzErweiterungen zur ProzesskontrolleSemaphore, Shared Memory and IPCSemaphore Funktionensem_release

Ein Service von Reinhard Neidl - Webprogrammierung.

Semaphore Funktionen

<<sem_get

sem_remove>>

sem_release

(PHP 4, PHP 5)

sem_releaseSemaphor freigeben

Beschreibung

bool sem_release ( resource $sem_identifier )

sem_release() gibt den angegebenen Semaphor frei, wenn er gegenwärtig vom aufrufenden Prozess gehalten wird; anderenfalls wird eine Warnung ausgegeben.

Nach der Freigabe eines Semaphors kann er mit sem_acquire() jederzeit wieder angefordert werden

Parameter-Liste

sem_identifier

Ein Semaphor-Ressourcehandle wie von sem_get() geliefert.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Siehe auch


2 BenutzerBeiträge:
- Beiträge aktualisieren...
danno at circumsolutions dot com
1.04.2001 23:44
If you want to implement this sort of semaphore access (which is usually what is needed if doing ipc) one thing you can do is create shared memory which is simply an int. Use this int between processes as the value of the semaphore.  You can write wrapper functions which use this to allow you to do the desired readers-writers stuff or just use the shared memory plain.  I wouldn't be too worried about race conditions in this case as the shared memory is only an int.  If you are worried about race conditions, the wrapper functions for doing the semaphore stuff could actually use a semaphore to elimate any race conditions.  Also, an added bonus of doing it this way is you can check the value of the int.
apua at communiplex dot com
8.12.1999 17:54
The fact that sem_release only resease the semaphore if it is currently acquired by the calling process is, in fact, a misfeature since sometimes (eg in a readers-writers implementation) it is desirable to release a semaphore acquired by another process. In C you can do that.
I'm telling this because I was trying to write a chat app in php3 made of two programs: a listener and a speaker. The speaker releases a semaphore to inform that there is a new message in a shared memory var. And listeners wait in that semaphore before outputting the message.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)