Dado que está ejecutando Linux, le recomendaría usar las API del temporizador POSIX incorporado.
int timer_create(clockid_t clockid, struct sigevent *sevp, timer_t *timerid);
Aquí hay un enlace a alguna documentation que muestra cómo utilizar temporizadores POSIX que proporcionan soporte para las funciones de devolución de llamada.
En cuanto a varios temporizadores en un proceso, la documentación dice esto:
A program may create multiple interval timers using timer_create().
Timers are not inherited by the child of a fork(2), and are disarmed and
deleted during an execve(2).
The kernel preallocates a "queued real-time signal" for each timer created
using timer_create(). Consequently, the number of timers is limited by the
RLIMIT_SIGPENDING resource limit (see setrlimit(2)).
debe comprender que el POSIX se pueden utilizar en una aplicación roscada mediante la creación de notificación mediante SIGEV_THREAD_ID como se muestra a continuación:
The sevp.sigev_notify field can have the following values:
SIGEV_NONE
Don't asynchronously notify when the timer expires. Progress of the
timer can be monitored using timer_gettime(2).
SIGEV_SIGNAL
Upon timer expiration, generate the signal sigev_signo for the process.
See sigevent(7) for general details. The si_code field of the
siginfo_t structure will be set to SI_TIMER. At any point in time, at
most one signal is queued to the process for a given timer; see
timer_getoverrun(2) for more details.
SIGEV_THREAD
Upon timer expiration, invoke sigev_notify_function as if it were the
start function of a new thread. See sigevent(7) for details.
SIGEV_THREAD_ID (Linux-specific)
As for SIGEV_SIGNAL, but the signal is targeted at the thread whose ID
is given in sigev_notify_thread_id, which must be a thread in the same
process as the caller. The sigev_notify_thread_id field specifies a
kernel thread ID, that is, the value returned by clone(2) or gettid(2).
This flag is only intended for use by threading libraries.
Por lo general es útil para explicar por qué esto está siendo votado/cerrado. –
¿Lo buscó? –
Esto está recibiendo votos cercanos porque es probable que solicite debate, argumentos, encuestas o discusiones extensas. Investiga un poco, intenta usar uno o más candidatos, pregúntale si tienes problemas con ellos. O pregunte, por ejemplo, _puedo usar el setitimer de POSIX en el código multiproceso_ ... esa es una buena pregunta – Useless