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
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 aSIGALRM
from the timer to the particular thread that calledsetitimer()
.
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.