tags:

views:

116

answers:

2

The source from here says that it is supposed to work on the iPhone. I have worked with it, but I get 2 errors, saying that msleep() is undeclared. I have tried to include unistd.h, time.h, and numerous others. How can I get this to work? Thanks.

+2  A: 

Err, I can find nothing in that linked thread stating that msleep is available. Someone implemented their own msleep:

#include <sys/time.h>
void msleep (unsigned int ms) {
    int microsecs;
    struct timeval tv;
    microsecs = ms * 1000;
    tv.tv_sec  = microsecs / 1000000;
    tv.tv_usec = microsecs % 1000000;
    select (0, NULL, NULL, NULL, &tv);  
}

but you should be careful since I think, from memory, that select is interruptable.

paxdiablo
A: 

The msleep() is a non-standard artifact from early BSDs, before the clock_nanosleep() and nanosleep() made it into POSIX.

It is unportable. On some systems it is available by default - on others one has to compile the code with _BSD_SOURCE define.

iPhone is a distant relative of Mac OS X, which is distant relative of NeXT, which is very distant relative of BSD 4.x. So the function might have stuck in some header/library somewhere, but you shouldn't use it anyway. If memory serves me right, check the NSThread's sleepForTimeInterval: static method.

Dummy00001