I'm using a pthread to schedule some tasks on my application. I copied the code from my old C version of the same application and it worked perfectly. Now I'm coding with C++ and it doesn't work anymore (basically it doesn't trigger the sigevent executing the given function). All creation and starting functions exit with rc 0, even when i use the timer_gettime.
I simplified a lot the code to narrow down the issue but I could't find it yet:
#include <signal.h>
#include <time.h>
int main (void)
{
char Mytimer[5] = "myt";
timer_t Ti_coarse;
Tcreate(Mytimer, &Ti_coarse, 1000, 1000);
while (1)
{
}
return 0;
static int Tcreate( char *name, timer_t *timerID, int expireMS, int intervalMS )
{
struct sigevent te;
struct itimerspec its;
struct sigaction sa;
int sigNo = SIGRTMIN;
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = app;
sigemptyset(&sa.sa_mask);
if (sigaction(sigNo, &sa, NULL) == -1)
{
perror("sigaction");
}
/* Set and enable alarm */
te.sigev_notify = SIGEV_SIGNAL;
te.sigev_signo = sigNo;
te.sigev_value.sival_ptr = timerID;
timer_create(CLOCK_REALTIME, &te, timerID);
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = intervalMS * 1000000;
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = expireMS * 1000000;
timer_settime(*timerID, 0, &its, NULL);
return 1;
}
static void app(int sig, siginfo_t *si, void *uc)
{
//do nothing
}
I expected to see the "THIS IS THE TIMERS" every second, but I don't get any output. If I check the expiration time of a 5 mins clock with printf("%d", its.it_value) I always get 299, no matter how much time passed.
Could you possible help me to spot the problem ?