Roland Schwarz wrote:
Johan Nilsson wrote:
Out of curiosity, who actually prefers using clock times for thread::sleep()? IIRC the implementation still converts the UTC time into a relative time before entering sleep, so it's only misleading to have an absolute time as parameter to sleep.
You would need to ask the pthreads folks. ;-) This behaviour is inherited from there.
Roland
That is kinda misleading. pthreads doesn't have a native sleep function. There were proposals for one, and some systems have a non-standard extension, but the usual way is to just call nanosleep(). In boost::threads, almost all of the code paths do in fact convert the absolute time into a relative duration. The only path that doesn't is when there is no nanosleep() and no pthread_delay_np() present; then the sleep is implemented by a pthread_cond_timedwait() which uses an absolute time, which has a resonable rationale for doing so. The rationale for using absolute times in a condition variable wait don't apply to sleep(), IMHO. The pthreads sleep extension uses relative time. There are alternatives to pthread_cond_timedwait() that don't use absolute time, for example select(). So a relative sleep is certainly implementable. Cheers, Ian McCulloch