Acquire Function

Action

Acquires a semaphore for the calling thread, if it is available.

Syntax

Acquire (sSemaphore) 
Variable Description
sSemaphore The semaphore to acquire. SEMAPHORE.

Notes

When you allocate a semaphore variable, you must initialize it to a value greater than zero before you can invoke Acquire. For example, the following statement creates a binary semaphore that allows you to control access to a single resource.

SEMAPHORE semAlpha = 1

Acquire decrements the value of the semaphore by one if the semaphore’s current value is greater than zero (0) and allows the calling thread to proceed (the semaphore has been "acquired"). If the semaphore’s value is zero, it blocks the calling thread until another thread releases the semaphore. When multiple threads are blocked on the same semaphore, Release unblocks them in the order in which they invoked Acquire.

If your script experiences an exception in the code between acquisition of a semaphore and its release, the script will deadlock unless you use a do-except statement to handle the exception. Place the do statement after the Acquire and before any code that could cause an exception. Place a Release statement in the except block.