sem_acquire

Acquire a semaphore

Description

bool sem_acquire(SysvSemaphore $semaphore, bool $non_blocking = false)

sem_acquire by default 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 maximum number of semaphore 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.

Parameters

semaphore

semaphore is a semaphore obtained from sem_get.

non_blocking

Specifies if the process shouldn't wait for the semaphore to be acquired. If set to true, the call will return false immediately if a semaphore cannot be immediately acquired.

Return Values

Returns true on success or false on failure.

Changelog

Version Description
8.0.0 semaphore expects a SysvSemaphore instance now; previously, a resource was expected.

See Also

  • sem_get
  • sem_release