Use sema_trywait(3C) to atomically decrement the count in the semaphore pointed to by sp when the count is greater than zero. This function is a nonblocking version of sema_wait().
#include <thread.h> int sema_trywait(sema_t *sp);
sp refers to an invalid semaphore.
The semaphore pointed to by sp has a zero count.