Semaphore and Shared Memory FunctionsSemaphore
This module provides semaphore functions using System V
semaphores. Semaphores may be used to provide exclusive access to
resources on the current machine, or to limit the number of
processes that may simultaneously use a resource.
This module provides also shared memory functions using System V
shared memory. Shared memory may be used to provide access to
global variables. Different httpd-daemons and even other programs
(such as Perl, C, ...) are able to access this data to provide a
global data-exchange. Remember, that shared memory is NOT safe
against simultaneous access. Use semaphores for synchronization.
Limits of Shared Memory by the Unix OSSHMMAXmax size of shared memory, normally 131072 bytesSHMMINminimum size of shared memory, normally 1 byteSHMMNImax amount of shared memory segments, normally 100SHMSEGmax amount of shared memory per process, normally 6
These functions do not work on Windows systems.
sem_getGet a semaphore idDescriptionint sem_getint keyint
max_acquireint
perm
Returns: A positive semaphore identifier on success, or false on
error.
Sem_get returns an id that can be used to
access the System V semaphore with the given key. The semaphore
is created if necessary using the permission bits specified in
perm (defaults to 0666). The number of processes that can
acquire the semaphore simultaneously is set to max_acquire
(defaults to 1). Actually this value is set only if the process
finds it is the only process currently attached to the semaphore.
A second call to sem_get for the same key
will return a different semaphore identifier, but both
identifiers access the same underlying semaphore.
See also: sem_acquire and
sem_release.
This function does not work on Windows systems
sem_acquireAcquire a semaphoreDescriptionint sem_acquireint sem_identifier
Returns: true on success, false on error.
Sem_acquire blocks (if necessary) until the
semaphore can be acquired. A process attempting to acquire a
semaphore which it has already acquired will block forever
if acquiring the semaphore would cause its max_acquire value to
be exceeded.
After processing a request, any semaphores acquired by the
process but not explicitly released will be released automatically
and a warning will be generated.
See also: sem_get and
sem_release.
sem_releaseRelease a semaphoreDescriptionint sem_releaseint sem_identifier
Returns: true on success, false on error.
Sem_release releases the semaphore if it
is currently acquired by the calling process, otherwise
a warning is generated.
After releasing the semaphore, sem_acquire
may be called to re-acquire it.
See also: sem_get and
sem_acquire.
This function does not work on Windows systems
shm_attachCreates or open a shared memory segmentDescriptionint shm_attachint keyint
memsizeint
permShm_attach returns an id that that can be
used to access the System V shared memory with the given key, the
first call creates the shared memory segment with mem_size
(default: sysvshm.init_mem in the configuration file, otherwise
10000 bytes) and the optional perm-bits (default: 0666).
A second call to shm_attach for the same
key will return a different shared memory
identifier, but both identifiers access the same underlying
shared memory. Memsize and
perm will be ignored.
This function does not work on Windows systems
shm_detachDisconnects from shared memory segmentDescriptionint shm_detachint shm_identifierShm_detach disconnects from the shared
memory given by the shm_identifier created
by shm_attach. Remember, that shared memory
still exist in the Unix system and the data is still present.
shm_removeRemoves shared memory from Unix systemsDescriptionint shm_removeint shm_identifier
Removes shared memory from Unix systems. All data will be
destroyed.
This function does not work on Windows systems
shm_put_varInserts or updates a variable in shared
memoryDescriptionint shm_put_varint shm_identifierint variable_keymixed variable
Inserts or updates a variable with a given
variable_key. All variable-types (double,
int, string, array) are supported.
This function does not work on Windows systems
shm_get_varReturns a variable from shared memory
Descriptionmixed shm_get_varint idint variable_keyShm_get_var returns the variable with a given
variable_key. The variable is still present
in the shared memory.
This function does not work on Windows systems
shm_remove_varRemoves a variable from shared memory
Descriptionint shm_remove_varint idint variable_key
Removes a variable with a given variable_key
and frees the occupied memory.
This function does not work on Windows systems