Multithreaded Programming Guide

Decrement a Semaphore Count

sema_trywait(3T)

#include <thread.h>

int sema_trywait(sema_t *sp);

Use sema_trywait() 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().