setitimer, SIGALRM & multithread process (linux, c)

后端 未结 2 904
[愿得一人]
[愿得一人] 2020-12-09 17:30

I want to use setitimer() (or less probable, the alarm()) in multithreaded process in linux 2.6+ with NPTL-enabled libc. Which thread will receive

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 18:23

    There was interesting topic in LKML in 2010 https://lkml.org/lkml/2010/4/11/81: "setitimer vs. threads: SIGALRM returned to which thread? (process master or individual child)" by Frantisek Rysanek (cz). Author says that setitimer used per-thread signals at least in times before Fedora 5:

    ... setitimer() had per-thread granularity. It used to deliver a SIGALRM from the timer to the particular thread that called setitimer().

    But in more recent Fedoras the behavior was changed ("man pthreads", ..."Threads do not share interval timers (fixed in kernel 2.6.12).")

    In the topic, Andi Kleen (Intel) recommends to switch to "POSIX timers (timer_create)"; and in ML thread Davide Libenzi suggests use of timerfd (timerfd_create, timerfd_settime) on non-ancient Linuxes.

提交回复
热议问题