A sample of thread sleep in Linux
2011-08-30
Our R&D Manager and senior system designer Mr. Mohamed gave us the following sample for a thread sleep in Linux.
#define _POSIX_C_SOURCE 199309
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
void mySleep()
{
int32_t retval
struct timespec requestTm, remainTm;
retval = 0
requestTm.tv_sec = 0;
requestTm.tv_nsec = 200000; //200ms
do
{
retval = nanosleep(&requestTm, &remainTm);
if((retval == -1) && (errno != ENITR))
retrun MBR_GAPDELAY_ERROR;
requestTm = remainTm;
}while (retVal != 0);