[SDL] Why not nanosleep()?

Mattias Engdegård f91-men at nada.kth.se
Tue Apr 4 12:31:25 PDT 2000


>Something that I have seen done, with varying amounts of sucess is something
>like: (Please excuse my pseudo-code)
>
>	starttime = gettimeofday()
>	if ( x < 10ms )		/* Give other processes a change */
>		sleep(0)

I don't think this is guaranteed to work very well. Historically sleep(0) has
meant "give up my time slice" but was never documented, and I won't complain
if it returns right away (I hear it does is some places).
Try sched_yield() instead.

>	} else {
>		usleep((x/(10ms))*10000us)

usleep() and nanosleep() want to sleep *at least* the requested
interval, but select() may timeout before its time, so it should be safer.




More information about the SDL mailing list