Ruby Threads From C

M

Mido Peace

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 ;)
 
R

Roger Pack

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
 
B

barjunk

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

-r

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.
 
R

Roger Pack

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
 
M

Mido Peace

Roger said:
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 )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top