nanosleep() hung

nanosleep() hung

Post by whererus » Fri, 15 Aug 2003 23:39:58


The following is my sleep function:

long nap(long period)
{
timespec_t rqtp, rmtp;

rqtp.tv_sec = period / 1000;
rqtp.tv_nsec = 1000000 * (period % 1000);
nanosleep(&rqtp, &rmtp);
}

When execute nap(10), sometimes it will be hung up.

My environment is SunOS 5.7 + gcc 2.8.1


--
Thanks,
Richard
 
 
 

nanosleep() hung

Post by Gianni Mar » Sat, 16 Aug 2003 03:13:08


This is probably a bug in SunOS or GCC ....

For kicks try:

long nap(long period)
{
/* if there is anything else in a timespec_t then */
/* this will initialize it. */
timespec_t rqtp = { 0 };

rqtp.tv_sec = period / 1000;
rqtp.tv_nsec = 1000000 * (period % 1000);
nanosleep(&rqtp, 0);

return 0; /* no return value ? */
}