[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Do C Extensions Block Ruby?

Nobuyoshi Nakada

9/19/2007 7:26:00 PM

Hi,

At Thu, 20 Sep 2007 04:22:09 +0900,
Wayne E. Seguin wrote in [ruby-talk:269902]:
> Does a C extension running in a ruby-thread block all ruby threads
> from running while it executes?

Yes.

--
Nobu Nakada

6 Answers

Joel VanderWerf

9/19/2007 9:16:00 PM

0

Nobuyoshi Nakada wrote:
> Hi,
>
> At Thu, 20 Sep 2007 04:22:09 +0900,
> Wayne E. Seguin wrote in [ruby-talk:269902]:
>> Does a C extension running in a ruby-thread block all ruby threads
>> from running while it executes?
>
> Yes.
>

...except when you call back into ruby from your C code (right?). Then
the thread scheduler could get a chance to do its thing.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Ilmari Heikkinen

9/20/2007 4:47:00 PM

0

On 9/20/07, Wayne E. Seguin <wayneeseguin@gmail.com> wrote:
> On Sep 19, 2007, at 17:15 , Joel VanderWerf wrote:
> > ...except when you call back into ruby from your C code (right?).
> > Then the thread scheduler could get a chance to do its thing.
> Joel,
>
> Thank you for the response.
>
> How do you call back? Is that the rb_thread_schedule() method?

Or rb_funcall(). Basically any call that executes ruby code.

Ran into an "interesting" bug with a C extension once with
this: I used a global scratchpad on the C side and did ruby calls
from C to log stuff. Which let other ruby threads hit the C side and
screw up the scratchpad. Resulting in some messed up images.

hemant

9/20/2007 5:02:00 PM

0

On 9/20/07, Ilmari Heikkinen <ilmari.heikkinen@gmail.com> wrote:
> On 9/20/07, Wayne E. Seguin <wayneeseguin@gmail.com> wrote:
> > On Sep 19, 2007, at 17:15 , Joel VanderWerf wrote:
> > > ...except when you call back into ruby from your C code (right?).
> > > Then the thread scheduler could get a chance to do its thing.
> > Joel,
> >
> > Thank you for the response.
> >
> > How do you call back? Is that the rb_thread_schedule() method?
>
> Or rb_funcall(). Basically any call that executes ruby code.
>

rb_funcall() is slow as shit, avoid it if you can.


> Ran into an "interesting" bug with a C extension once with
> this: I used a global scratchpad on the C side and did ruby calls
> from C to log stuff. Which let other ruby threads hit the C side and
> screw up the scratchpad. Resulting in some messed up images.
>
>


--
Let them talk of their oriental summer climes of everlasting
conservatories; give me the privilege of making my own summer with my
own coals.

http://g...

Ilmari Heikkinen

9/20/2007 5:41:00 PM

0

On 9/20/07, hemant <gethemant@gmail.com> wrote:
> On 9/20/07, Ilmari Heikkinen <ilmari.heikkinen@gmail.com> wrote:
> > On 9/20/07, Wayne E. Seguin <wayneeseguin@gmail.com> wrote:
> > > On Sep 19, 2007, at 17:15 , Joel VanderWerf wrote:
> > > > ...except when you call back into ruby from your C code (right?).
> > > > Then the thread scheduler could get a chance to do its thing.
> > > Joel,
> > >
> > > Thank you for the response.
> > >
> > > How do you call back? Is that the rb_thread_schedule() method?
> >
> > Or rb_funcall(). Basically any call that executes ruby code.
> >
>
> rb_funcall() is slow as shit, avoid it if you can.
>

And logging touches disk, not like the 10 usec or so spent in rb_funcall
is going to do much difference there :|

Eric Hodel

9/20/2007 7:28:00 PM

0

On Sep 20, 2007, at 11:06, Wayne E. Seguin wrote:
> On Sep 20, 2007, at 13:40 , Ilmari Heikkinen wrote:
>> And logging touches disk, not like the 10 usec or so spent in
>> rb_funcall
>> is going to do much difference there :|
>
> Actually the reason that I brought this question up is that I am
> working on an asynchronous logger for Ruby whose main purpose is to
> remove the Blocking IO time from the equation in order to greatly
> speed up production apps running on a POSIX compliant OS.
> The project is on rubyforge as "AlogR" but is not ready to be
> released just yet.
> Suggestions are most welcome :)

Most of the C functions in IO will allow threads to be switched.
Eventually they run into rb_thread_schedule(). You can get non-
blocking IO without writing C code, IO can handle that for you.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars



Eric Hodel

9/20/2007 9:12:00 PM

0

On Sep 20, 2007, at 12:36, Wayne E. Seguin wrote:
> On Sep 20, 2007, at 15:27 , Eric Hodel wrote:
>> Most of the C functions in IO will allow threads to be switched.
>> Eventually they run into rb_thread_schedule(). You can get non-
>> blocking IO without writing C code, IO can handle that for you.
>
> Can you provide me with an example or point me to a url to RTFM?

io/nonblock.rb and IO#read_nonblock should get you started.

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars