mq_send 是原子的吗?

发布于 2024-08-08 21:57:41 字数 52 浏览 2 评论 0原文

谁能告诉我如果多线程程序在执行 mq_send 期间收到 SIGSTOP 信号会发生什么?

can anybody tell me what happens if multithread program receives SIGSTOP signal during execution of mq_send?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

独自←快乐 2024-08-15 21:57:41

mq_send 的手册页表明它是在 mq_timedsend(Linux 中的系统调用)之上实现的。系统调用通常是原子的,因为它们要么成功,要么不成功。如果系统调用被信号中断,通常的行为是返回 -1 并将 errno 设置为 EINTR。看起来mq_send有这种行为。

基本上,您应该检查 EINTR,如果以这种方式失败,则重试调用。这对于像 recvselect 这样可能阻塞的系统调用尤其重要,因为它们更有可能被中断。

The man page for mq_send indicates it is implemented on top of mq_timedsend, which is a system call in Linux. System calls are generally atomic in that they either succeed or they don't. If a system call is interrupted by a signal, the usual behavior is to return -1 and set errno to EINTR. It looks like mq_send has this behavior.

Basically, you should check for EINTR, and retry the call if it fails in this way. This is particularly important for system calls that may block like recv or select, since they have a higher chance of being interrupted.

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