Cicode Programming Reference > Cicode Function Categories > Task Functions Introduction > SemWait


Waits on a semaphore to be signalled. This function is a blocking function. It will block the calling Cicode task until the operation is complete.

Note: This function is process-based, not computer-based, and so will only prevent access to a critical section within a single process. This function only works between Cicode tasks within the same process.


SemWait(hSem, Timeout)


The semaphore handle, returned from the SemOpen() function. The semaphore handle identifies the table where all data on the associated semaphore is stored.


Semaphore time-out time:

-1 - Wait until semaphore is clear (regardless of how long).

0 - Do not wait - return immediately. (This timeout can be used to check the state.)

> 0 - The number of seconds to wait if semaphore is not signalling, then return.

Return Value

0 (zero) if the semaphore has been gained, otherwise an error is returned.

Related Functions

SemClose, SemOpen, SemSignal


IF Status=0 THEN
Prompt("Could not get semaphore");

See Also

Task Functions