Hello guys,

I'm writing a opensync metamodule in order to allow opensync modules
written in ruby.
It already exists for python but I am a ruby guy. It is almost
complete except to the fact
 that is segfalts :-) I'm using ruby 1.9.1.

Opensync is multithreaded by design. So, my module must accept this behavior.
I mutexed all ruby access in order to avoid concurrent access of ruby env.

If this is offtopic for this list, please, sorry and let me know.

Currently, my initialization (ruby_init, RUBY_INIT_STACK,...) run
inside the main thread and all following calls works with no problem.
However, when the first non-main thread GC, it segfalts. Is it allowed
to call ruby from a child thread?

I debugged and what I think that I noticed is that GC scans from
current thread stack to the machine "stack end". For the main thread,
this is OK. However, when it is a child thread, between the child
stack and the main stack, there is some unallocated memory, which
segfalts on access. Something like this:

[child_stack_start...child_stack_end] unallocated
[main_stack_start...main_stack_end]

If I disable GC, it runs flawless. Is it a possible solution to
disable GC when running a method inside a pthread and reenable it when
main thread calls a method? Would it miss (not free) some objects
inside pthread stack?

One good solution would be some workarround in order to allow calls
and GC from any thread as the one I proposed. Is it possible?

Another great solution would be to allow all ruby stuck exclusively
inside a pthread. This way, I could isolate ruby in a dedicated
pthread with a dedicated stack. All other threads would use ruby
though this thread. However, my current knowledge tells me that ruby
must live inside the main thread (it depends on the main thread stack
end address). Am I right? Is something like running ruby from a single
pthread possible?

The best solution would be to allow ruby initialization inside any
pthread and ruby calls from any pthread. I guess ruby is too far away
from this one ;-)

I was hoping that 1.9.x would help me in any way as it uses pthreads
for ruby threads but I noticed no difference.

I really searched hard to find a solution before getting to the list
but nothing helped. Maybe ruby_bind_stack patch could help but I don't
think it would get upstream too soon.

Thanks,

---
  Luiz Angelo Daros de Luca, Me.
      luizluca / gmail.com