semWait (Function) |
Top Previous Next |
The semWait() function will perform a traditional WAIT operation on the specified semaphore. The semWait() mechanism will: •When the semaphore value>0, it will decrement the semaphore value and the calling thread will continue to execute. •When the semaphore value=0, it will block the calling thread on a FIFO queue waiting for another thread to call semSignal().
The semaphore mechanism can be used for a big range of different synchronization tasks. It can also be used to implement critical sections, like the Mutex mechanism, but for that purpose the Mutex is better suited. The semWait() operation also offers a timeout facility to reduce the time waiting for the semaphore.
Also see the section on thread synchronization for more information.
Input: sem : SEMAPHORE The semaphore to wait for.
timeout : INT (default: -1 forever) The time, in ms., to wait for the semaphore to be signaled. Use -1 to wait forever. This is the default.
Returns: INT
Declaration: FUNCTION semWait : INT;
Example: INCLUDE rtcu.inc |