The sem_tgrab function tests and requests exclusive use of a semaphore. Unlike the similar sem_grab function, if exclusive access is unavailable the caller is not blocked but receives a return value of -1. Use this function to ensure that only one server processor thread performs an action at a time.
#include <base/sem.h> int sem_grab(SEMAPHORE id);
-1 if an error occurred or if exclusive access was not available
0 exclusive access was granted
SEMAPHORE id is the unique identification number of the semaphore.