信号量意外设置

发布于 2024-12-22 04:40:02 字数 457 浏览 4 评论 0原文

可能的重复:
进程间信号量有时无法按预期工作

在我的应用程序中,我注意到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷遇一生 2024-12-29 04:40:02

您链接到的代码不会捕获 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.g sem_wait can return prematurely, so-called spurious wakeups.

Always check the return codes of these functions. If the return is -1 check errno for the corresponding error and decide if it is a transient error. If so, iterate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文