c / interrupted system call / fork vs. thread

后端 未结 2 1254
说谎
说谎 2021-01-13 17:24

I discovered an issue with thread implementation, that is strange to me. Maybe some of you can explain it to me, would be great.

I am working on something like a pro

2条回答
  •  执念已碎
    2021-01-13 17:43

    EINTR does not itself indicate an error. It means that your process received a signal while it was in the sendto syscall, and that syscall hadn't sent any data yet (that's important).

    You could retry the send in this case, but a good thing would be to figure out what signal caused the interruption. If this is reproducible, try using strace.

    If you're the one sending the signal, well, you know what to do :-)

    Note that on linux, you can receive EINTR on sendto (and some other functions) even if you haven't installed a handler yourself. This can happen if:

  • the process is stopped (via SIGSTOP for example) and restarted (with SIGCONT)
  • you have set a send timeout on the socket (via SO_SNDTIMEO)

    See the signal(7) man page (at the very bottom) for more details.

    So if you're "suspending" your service (or something else is), that EINTR is expected and you should restart the call.

提交回复
热议问题