Thanks for your reply.
Based on my code instrumentation and logs, timer fires at various rates. So lock is not grabbed at a constant intervals.
You should be able to repo this easily, For example, you could have to int counters in shared memory. One counter is incremented by the consumer and the other by producer. print the counters after lock and before unlock.
int create_timer() {
timer_t timerid;
struct sigevent se;
memset(&se, 0, sizeof(struct sigevent));
se.sigev_notify_function = consumer;
se.sigev_notify = SIGEV_THREAD;
se.sigev_value.sival_ptr = &timerid;
se.sigev_notify_attributes = NULL;
int status = timer_create(CLOCK_BOOTTIME, &se, &timerid);
if (status != 0) {
LOG("failed to create timer: %s", strerror(errno));
return status;
}
struct itimerspec ts;
ts.it_value.tv_sec = 0;
ts.it_value.tv_nsec = 9000000; // 9 milli seconds
ts.it_interval.tv_sec = 0;
ts.it_interval.tv_nsec = 4000000; // 4 milli seconds
status = timer_settime(timerid, 0, &ts, NULL);
if (status == -1) {
LOG("failed to settimer, %s", strerror(errno));
}
return status;
}