Error in ruby extension

hi,
Question related to extending ruby
I have a class derived from a swigged c++ class
i.e.

class MyClass < Gm:GMClass

    def initialize()
            super()
    end

    def construct()
            @node = Gm::GMNode.new("name")
            #just to test
            ObjectSpace.garbage_collect
    end

end

I create an instance of MyClass using rb_load_protect and
then call the construct method using rb_funcall. The problem is
that if I create the instance in one c++ thread and then call the
construct method in another c++ thread I get the following error
when gc is invoked

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 8194 (LWP 1036)]
mark_locations_array (x=0x41845000, n=530508239) at gc.c:501

#1 0x08072c89 in rb_gc () at gc.c:1208
#2 0x08072d7b in rb_gc_start () at gc.c:1245
#3 0x0806ced3 in call_cfunc (func=0x8072d70 <rb_gc_start>, recv=1090738928,
len=0, argc=0, argv=0x0) at eval.c:4547
#4 0x08063019 in rb_call0 (klass=1090738868, recv=1090738928, id=9505,
oid=0, argc=0, argv=0x0, body=0x41035a50, nosuper=1) at eval.c:4684
#5 0x080637a1 in rb_call (klass=1090738868, recv=1090738928, mid=9505,
argc=0, argv=0x0, scope=0) at eval.c:4901
#6 0x0805f05b in rb_eval (self=1090733368, n=0x0) at eval.c:2816
#7 0x080632f8 in rb_call0 (klass=1090733588, recv=1090733368, id=10053,
oid=0, argc=0, argv=0x418449e0, body=0x41034920, nosuper=0) at eval.c:4812
#8 0x080637a1 in rb_call (klass=1090733588, recv=1090733368, mid=10053,
argc=1, argv=0x418449dc, scope=1) at eval.c:4901
#9 0x08063a73 in rb_funcall2 (recv=0, mid=10053, argc=1, argv=0x418449dc)
at ruby.h:615

The problem dissapears if call both from the same thread. I do remember
seeing something about ruby not being thread safe but can’t now find where
I saw this
I’m using ruby 1.8.0 (2003-03-03) [i686-linux], swig 1.3.19
Any help much appreciated
Cheers

You are completely right, Ruby isn’t thread-safe and there’s not much
you can do about it :expressionless: unless you wait for Rite or get rid of all
globals in the interpreter…

···

On Thu, Apr 24, 2003 at 09:08:48PM +0900, Steve Hart wrote:

The problem dissapears if call both from the same thread. I do remember
seeing something about ruby not being thread safe but can’t now find where
I saw this
I’m using ruby 1.8.0 (2003-03-03) [i686-linux], swig 1.3.19
Any help much appreciated


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Save yourself from the ‘Gates’ of hell, use Linux." – like that one.
– The_Kind @ LinuxNet

In answer to my own question and in hope of confirmation, it would appear
that multithreading ruby extensions is not possible. I am assuming this is
because GC checks the current threads stack during mark and sweep. If I
create an class instance in one thread and use this to access a method of
that class in another thread I screw up the GC. Is it the case that all
ruby extensions may only be called from the thread that initialises the
ruby interpreter (i.e. the one that calls ruby_init()?

Mauricio Fernández wrote:

···

On Thu, Apr 24, 2003 at 09:08:48PM +0900, Steve Hart wrote:

The problem dissapears if call both from the same thread. I do remember
seeing something about ruby not being thread safe but can’t now find
where I saw this
I’m using ruby 1.8.0 (2003-03-03) [i686-linux], swig 1.3.19
Any help much appreciated

You are completely right, Ruby isn’t thread-safe and there’s not much
you can do about it :expressionless: unless you wait for Rite or get rid of all
globals in the interpreter…

Thanks for the confirmation Mauricio - I can work around.
So what (and when) is Rite

The upcoming new Ruby (bytecode) interpreter.
There’s good chances it will rock; the sad thing is that it’s still
vapourware :expressionless:

···

On Mon, Apr 28, 2003 at 05:00:21PM +0900, Steve Hart wrote:

The problem dissapears if call both from the same thread. I do remember
seeing something about ruby not being thread safe but can’t now find
where I saw this
I’m using ruby 1.8.0 (2003-03-03) [i686-linux], swig 1.3.19
Any help much appreciated

You are completely right, Ruby isn’t thread-safe and there’s not much
you can do about it :expressionless: unless you wait for Rite or get rid of all
globals in the interpreter…

Thanks for the confirmation Mauricio - I can work around.
So what (and when) is Rite


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

  • LG loves czech girls.
    LG: do they have additional interesting “features” other girls don’t have? :wink:
    #Debian