sem_getvalue() dysfunctionality in Mac OS X - C++

我是研究僧i 提交于 2019-11-28 02:01:57

I think you are asking, "how can I work around the absence of sem_getvalue() on OS X?"

I can think of three approaches:

First (and best, in my opinion) redesign your program so that the current value of the semaphore is never needed. After all, as the documentation warns, the value reported by sem_getvalue isn't necessarily accurate by the time it is received.

Second, if necessary, wrap the POSIX semaphore functions and keep your own count. Every sem_t can be adorned by a counter and a mutex protecting that counter. Your implementation probably will have (and probably should have!) the same caveat as sem_getvalue, that is, the count can't be trusted to be accurate once it is retrieved.

Third, and least palatable in my opinion, switch to the older and more complicated SysV semaphore IPC interface. That implements something analogous to sem_getvalue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!