From: Sam Roberts Date: 2005-02-18T22:31:55+09:00 Subject: Re: pulling my hair out, why won't Kernel.sleep(0) sleep? Quoteing matz@ruby-lang.org, on Fri, Feb 18, 2005 at 01:50:26PM +0900: > Hi, > > |Do you have any idea why this should be? What does Kernel.sleep(0) > |actually do? > > I guess it was busy looping, but there were other threads to work > sometimes. sleep(0) does not sleep but causes context switch. That describes what I saw, kindof (race conditions are inherently weird). Thanks, Sam Here's a start to the docs, but I don't know if my description is correct! /* * call-seq: - * sleep(duration=0) => fixnum + * sleep(duration) => fixnum + * sleep() => fixnum * - * Suspends the current thread for _duration_ seconds (which may be - * any number, including a +Float+ with fractional seconds). Returns the actual - * number of seconds slept (rounded), which may be less than that asked - * for if the thread was interrupted by a +SIGALRM+, or if - * another thread calls Thread#run. An argument of zero - * causes +sleep+ to sleep forever. - * + * Suspends the current thread for _duration_ seconds (which may be any + * number, including a +Float+ with fractional seconds). Calling sleep with + * no arguments causes +sleep+ to sleep "forever" - where "forever" means + * until it is woken up, see below. Calling sleep with an argument of + * +0+ causes a context switch, if another thread is ready to be + * scheduled. + * + * Returns the actual number of seconds slept (rounded), which may be less + * than that asked for if the thread was interrupted by a +SIGALRM+, or if + * another thread calls Thread#run. + * + * WHAT ABOUT OTHER SIGNALS? + * * Time.new #=> Wed Apr 09 08:56:32 CDT 2003 * sleep 1.2 #=> 1 * Time.new #=> Wed Apr 09 08:56:33 CDT 2003