I am trying to apply C multithreading to a ruby class method
Here is the code:
require ''inline''
class Example
  inline :C do |builder|
  builder.include "<pthread.h>"
    builder.c ''
    static void run_thread(VALUE name){
        // I added a ruby User class to test posting a variable from
thread to db
        VALUE user = rb_const_get( rb_cObject, rb_intern("User") );
        rb_funcall(user, rb_intern("add"), 1, name);
    }''
    builder.c ''
    static void simple(VALUE name){
        run_thread(self, name);
    }''
    builder.c ''
    static void threads(VALUE name){
        pthread_t pth;
        pthread_create(&pth, NULL, (void *)run_thread, (VALUE *)name );
        pthread_join(pth, NULL);
    }''
end
end
if I run Example.new.run_thread("Adam") i get the expected result
---------
(0.3ms)  BEGIN
SQL (19.9ms)  INSERT INTO `users` (`created_at`, `name`, `updated_at`)
VALUES (''2012-03-16 04:53:15'', ''Adam'',
''2012-03-16 04:53:15'')
(0.5ms)  COMMIT
if I run Example.new.simple("Adam") I get the expected result
---------
(0.3ms)  BEGIN
SQL (19.9ms)  INSERT INTO `users` (`created_at`, `name`, `updated_at`)
VALUES (''2012-03-16 04:53:15'', ''Adam'',
''2012-03-16 04:53:15'')
(0.5ms)  COMMIT
if I run Example.new.threads("Adam") i get the error
---------
[FATAL] failed to allocate memory
I think the problem is that I am not passing the VALUE properly to
thread.
I would need guidance with this please. Thank you.
-- 
Posted via http://www.ruby-forum.com/.
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.