I think you are asking: "How can I get around the lack of sem_getvalue() in OS X?"
I can think of three approaches:
First (and best of all, in my opinion) redesign your program so that the current semaphore value is never required. After all, as the documentation warns , the value reported by sem_getvalue will not necessarily be accurate at the time it is received.
Secondly, if necessary, wrap the POSIX semaphore functions and save your own score. Each sem_t can be decorated with a counter and a mutex protecting this counter. Your implementation will probably (and probably should be!) The same caveat as sem_getvalue , i.e. It cannot be considered that the counter may be accurate after receiving it.
Third, and in my opinion the least acceptable, switch to the older and more complex SysV IPC semaphore interface . This implements something similar to sem_getvalue .
pilcrow May 20 '13 at 18:05 2013-05-20 18:05
source share