mq_send 是原子的吗?
谁能告诉我如果多线程程序在执行 mq_send 期间收到 SIGSTOP 信号会发生什么?
can anybody tell me what happens if multithread program receives SIGSTOP signal during execution of mq_send?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mq_send
的手册页表明它是在mq_timedsend
(Linux 中的系统调用)之上实现的。系统调用通常是原子的,因为它们要么成功,要么不成功。如果系统调用被信号中断,通常的行为是返回 -1 并将 errno 设置为 EINTR。看起来mq_send
有这种行为。基本上,您应该检查
EINTR
,如果以这种方式失败,则重试调用。这对于像recv
或select
这样可能阻塞的系统调用尤其重要,因为它们更有可能被中断。The man page for
mq_send
indicates it is implemented on top ofmq_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 seterrno
toEINTR
. It looks likemq_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 likerecv
orselect
, since they have a higher chance of being interrupted.