信号量意外设置
可能的重复:
进程间信号量有时无法按预期工作
在我的应用程序中,我注意到sem_t 类型的信号量有时会从 0 变为 1,而不执行 sem_post。怎么会?什么会导致这种情况?信号量用于进程间通信,您可以在此处查看代码< /a>.
Possible Duplicate:
Interprocess semaphores sometimes not working as expected
In my application, I notice that a semaphore of type sem_t sometimes become 1 from 0 without executing sem_post. How come? What can cause this? The semaphore is used for inter-process communication and you can look at the code here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您链接到的代码不会捕获
sem_t
调用的返回值。如果您查看手册,您会发现例如sem_wait
可能会过早返回,即所谓的虚假唤醒。请务必检查这些函数的返回码。如果返回
-1
,请检查errno
是否有相应的错误,并确定是否是暂时性错误。如果是这样,请迭代。The code that you are linking to doesn't capture the return values from the
sem_t
calls. If you look in the manual you can see that e.gsem_wait
can return prematurely, so-called spurious wakeups.Always check the return codes of these functions. If the return is
-1
checkerrno
for the corresponding error and decide if it is a transient error. If so, iterate.