The code uses multiple threads with timers. We do not share timers between
threads. The code does not always fail when timer_gettime is called, but
when it does the next timer_gettime call works. The return values for sec
and nsec are zero and the return code is 22, Invalid Argument.
long sec, nsec, time;
struct itimerspec m_itime, m_value;
struct sigevent m_event;
SIGEV_NONE_INIT(&m_event);
timer_create(CLOCK_REALTIME, &m_event, &m_timer_id);
m_itime.it_value.tv_sec = 10;
m_itime.it_value.tv_nsec = 0;
m_itime.it_interval.tv_sec = 0;
m_itime.it_interval.tv_nsec = 0;
timer_settime(m_timer_id, 0, &m_itime, NULL);
// Some code for about 5 seconds
if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,“timer_gettime failed %s”, strerror(errno));
if (timer_gettime(m_timer_id, &m_value) != 0)
{
trace(TRDEV, TRACE_ERROR,“timer_gettime failed again %s”,
strerror(errno));
}
}
sec = m_value.it_value.tv_sec;
nsec = m_value.it_value.tv_nsec;
time = (long)((sec*1000.0) + (nsec/1000000.0)); // converts secs/nsecs to
msecs
return time;
“Adam Mallory” <amallory@qnx.com> wrote in message
news:bfmf3e$s5j$1@nntp.qnx.com…
M. Hagerman <> hagerman@battelle.org> > wrote in message
news:bfmbeh$drt$> 1@inn.qnx.com> …
But, if I immediatley call get_time again after the error the function
returns the correct value. If the timer did’nt exist or was invalid,
wouldn’t the next call fail as well.
I’m not familar with your code, but if another thread happened to make a
timer, the ID might be reused.
If it’s this basic, post a test case illustrating the problem so we can
take
a look.
-Adam