From: Paul Brannan Date: 2004-03-13T05:17:19+09:00 Subject: Re: How to write a blocking ruby function in c ? On Fri, Mar 12, 2004 at 03:44:34PM +0900, Lothar Scholz wrote: > So i think i should write the following function: > > VALUE read_data (VALUE self, VALUE from) > { > if ( ...from has no data....) rb_thread_stop(); > data = .... read data from subsystem > return data; > } > > but how can i do the thread wakeup call ? I think what you want is something like this: 1. See if you have data waiting; if you do read and return. 2. If there is no data waiting, then call rb_thread_select with your file descriptor to wait on data. 3. When rb_thread_select returns, read and return the data. If not enough data is available, call rb_thread_select again and repeat. Paul