I need to do the following for a C++ assessment I'm taking. I've never used the select function before and can't find much on it. The question is:
Write a thread-safe implementation of sleep without using nanosleep. Make use of select in your implementation.
an example I found is:
int usleep(long usec)
{
struct timeval tv;
tv.tv_sec = usec/1000000L;
tv.tv_usec = usec%1000000L;
return select(0, 0, 0, 0, &tv);
}
You probably need to provide a valid fd. You have stdin, stdout, stderr. You can make them block my waiting for output from stdin or input from stdout or stderr.