Arm Mbed OS support forum

Semaphore for thread access counting

Hello,

implementations of semaphores often allow me to get the current number of acquisitions from different threads. Why am I not able to get the current count for mbed semaphores? Wouldn’t it be helpful to get the number of remaining threads that can enter the semaphore object?

Something like:
Semaphore sema(10);
sema.acquire();
sema.count(); // returns 1 or 9, depending on the implementation

Implementation would look like
uint16_t Semaphore::count()
{
#if MBED_CONF_RTOS_PRESENT
return osSemaphoreGetCount(_id);
#else

#endif
}

Thank you.