Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » SQL Anywhere Server - SQL Reference » SQL statements » Alphabetical list of SQL statements

WAITFOR SEMAPHORE statement

Decrements the counter associated with a semaphore.

Syntax
WAITFOR SEMAPHORE [ owner.]semaphore-name 
[ TIMEOUT number-milliseconds ] 
Parameters
  • owner

    The owner of the semaphore. owner can also be specified using an indirect identifier (for example, `[@variable-name]`).

  • semaphore-name

    The name of the semaphore. semaphore-name can also be specified using an indirect identifier (for example, `[@variable-name]`).

  • TIMEOUT clause

    Specify the duration of time, in milliseconds, to wait to decrement the counter associated with the semaphore. If this clause is not specified, then the connection waits indefinitely until the count can be decremented, or until an error is returned.

    number-milliseconds can be specified using a variable (for example, TIMEOUT @timeout-value). If number-milliseconds is set to a variable and the variable is NULL, the behavior is equivalent to not specifying the clause.

Remarks

The WAITFOR SEMAPHORE statement decrements the counter associated with the semaphore. If the counter is a positive integer, then the count is decremented and the statement completes. If the counter is 0, then the connection waits until the counter is a positive integer, or until the duration specified by the TIMEOUT clause passes, at which point an error is returned indicating the timeout.

An error is returned if the current connection is identified during deadlock detection while waiting on the semaphore. An error is also returned if the semaphore is dropped.

If a connection that notified a semaphore is dropped or canceled, the counter decrement persists, so your application needs to be able to address this case.

Privileges

You must have the UPDATE ANY MUTEX SEMAPHORE system privilege, or be the owner of the semaphore.

Side effects

None.

Standards
  • ANSI/ISO SQL Standard

    Not in the standard.

Example

The following statement decrements the counter for the license_counter semaphore by 1. If the semaphore count is 0, then the statement waits indefinitely until the counter is incremented.

WAITFOR SEMAPHORE license_counter;