Ruby Threads From C

Hi,

I'd like to know how can I do to create ( or instantiate ) a Ruby Thread
from C .
actually , I have to Bind Some C Modules to Ruby , So I have to manage
The ruby Thread inside my C code ( Start , Stop , Resume ...ect )

Thx :wink:

路路路

--
Posted via http://www.ruby-forum.com/.

I'd like to know how can I do to create ( or instantiate ) a Ruby Thread
from C .

I'd just lookup the Thread class and call a "new" on it, passing it a
block.

-r

路路路

--
Posted via http://www.ruby-forum.com/\.

Do you you have an example of doing this from within C that you can
point to? My C isn't at an expert level, and I've had some trouble
finding an example that I can work with to do this sort of thing.

Thanks for any links or ideas.

Mike B.

路路路

On Feb 2, 7:45 am, Roger Pack <rogerpack2...@gmail.com> wrote:

> I'd like to know how can I do to create ( or instantiate ) a Ruby Thread
> from C .

I'd just lookup the Thread class and call a "new" on it, passing it a
block.

-r

--
Posted viahttp://www.ruby-forum.com/.

Do you you have an example of doing this from within C that you can
point to? My C isn't at an expert level, and I've had some trouble
finding an example that I can work with to do this sort of thing.

Appears there's also an rb_thread_create, though I have no idea how to
use it.

http://betterlogic.com/roger/?p=2474&cpage=1#comment-3372

might work...the kicker though is that if you're looking for something
like

rb_go_and_do_this_in_some_other_thread("stuff")

Then I don't think using ruby's C API to start a thread will work--you
may need to run the ruby code in a separate C thread.

GL!
-r

路路路

--
Posted via http://www.ruby-forum.com/\.

Roger Pack wrote:

Do you you have an example of doing this from within C that you can
point to? My C isn't at an expert level, and I've had some trouble
finding an example that I can work with to do this sort of thing.

Appears there's also an rb_thread_create, though I have no idea how to
use it.

http://betterlogic.com/roger/?p=2474&cpage=1#comment-3372

might work...the kicker though is that if you're looking for something
like

rb_go_and_do_this_in_some_other_thread("stuff")

Then I don't think using ruby's C API to start a thread will work--you
may need to run the ruby code in a separate C thread.

GL!
-r

Actually , I tried :

rb_funcall3(rb_const_get(rb_cObject, rb_intern("Thread")),
rb_intern("new"), 0, 0);

But >> `initialize': must be called with a block (ThreadError)

it seems like the Thread Class should always be called with a Block of
instrcution to execute as we do with Ruby Code Thread.new{ do .. this ..
ect }

I found Some C Methods to deal with Ruby Thread :
...
VALUE rb_thread_stop (void)
VALUE rb_thread_wakeup (VALUE)
VALUE rb_thread_run (VALUE)
VALUE rb_thread_kill (VALUE)
VALUE rb_thread_create (VALUE(*(ANYARGS), void *))
void rb_thread_interrupt (void)
void rb_thread_trap_eval (VALUE, int)
void rb_thread_signal_raise (char *)
int rb_thread_select (ANYARGS)
void rb_thread_wait_for (ANYARGS)
VALUE rb_thread_current (void)
VALUE rb_thread_main (void)
...
http://ruby-doc.org/doxygen/1.8.4/group__ruby__eval.html

But not yet sure that it really create and manage a Ruby Thread (
especially that this One should be always initialized with a block of
instructions )

路路路

--
Posted via http://www.ruby-forum.com/\.

Actually , I tried :

rb_funcall3(rb_const_get(rb_cObject, rb_intern("Thread")),
rb_intern("new"), 0, 0);

But >> `initialize': must be called with a block (ThreadError)

The code at

http://betterlogic.com/roger/?p=2474&cpage=1#comment-3372

uses rb_iterate which "passes a block" to a method.
-r

路路路

--
Posted via http://www.ruby-forum.com/\.