From: Tomas Pospisek's Mailing Lists Date: 2007-03-02T06:16:26+09:00 Subject: Re: replacing the use of gettimeofday in the scheduler On Fri, 2 Mar 2007, Avdi Grimm wrote: > On 3/1/07, Eric Hodel wrote: >> The Ruby thread scheduler uses setitimer(2) and select(2). It >> depends on the wall-clock for implementing features defined in terms >> of the wall-clock (Kernel#sleep and Thread#join). > > > > Thanks for the explanation. I'm probably missing something, I'm > confused by why the functionality you describe in Kernel#sleep and > Thread#join can't be implemented using only select(). Can you clarify? It *is* implemented using select, but select is, per spec, allowed to return before the time's up. So rb_thread_wait_for(time) is (indirectly) using gettimeofday to find out how much time has gone by. And if (diff = (gettimeofday_now - gettimeofday_before_we_called_select) > 0 ) then rb_thread_wait_for reiterates and sleeps (with select) again. I can see the following solutions: * find a reliable time source that works cross-platform. uptime and ticks would be candidates, but I haven't found a way to have them cross-platform. * use thread_timer as a reliable time source *t -- ----------------------------------------------------------- Tomas Pospisek http://sourcepole.com - Linux & Open Source Solutions -----------------------------------------------------------