In the embedded system I am currently developing, various methods are used for periodic processing. Among them, the method of setting SIGEV_THREAD in sigev_notify of the sigevent structure with the timer_create function and starting the specified function as one thread (timer thread) after a certain period of time is one of the commonly used methods. In the system under development, there are a plurality of places where a periodic timer is realized by this method, and when the system is started, the timer thread is always generated and terminated. At this time, I was wondering where each of the generated timer threads was created, so I looked up the thread name of the timer thread. (Because I thought that the name of the timer thread and the name of the thread that called timer_create match.) Then, all the generated timer threads had the same thread name. Therefore, I investigated the operation of the periodic timer when SIGEV_THREAD was set in timer_create.
int timer_create(clockid_t clockid, struct sigevent *restrict evp, timer_t *restrict timerid)
argument: First argument: Clock ID Second argument: sigevent information → Details Third argument: Pointer for storing timer ID
Create a timer for each process. When the timer expires, the operation set by sigevent is performed. (Set the cycle time and start the timer with the timer_settime function.)
When the first timer with SIGEV_THREAD set is created, a timer thread for starting is created when the timer expires. (The thread name of the parent thread is inherited.) When the timer expires, the function specified in the first generated timer thread is started. → Even if multiple timers with SIGEV_THREAD set are created, the function is started in the timer thread created first. Therefore, the timer thread name is different from the thread that created the timer, except for the thread that created the timer thread. However, if another timer expires while the timer thread is already running, a new timer thread is created. (The thread name at this time is the same as the thread name that starts when the timer expires. When the function ends, the timer thread ends immediately.)
This article was written with reference to the following information.
timer_create() manual http://www.yosbits.com/opensonar/rest/man/freebsd/man/ja/man2/timer_create.2.html
SIGEVENT manual https://linuxjm.osdn.jp/html/LDP_man-pages/man7/sigevent.7.html
Recommended Posts