Embed ruby in a threaded C++ Application (Mingw)

I’ll try to explain the current status of my application :

I have a Qt4 Application which runs on Windows (thanks to Mingw).
In one thread created by this application, I would like to use the Ruby
1.8.2
engine (to evaluate a script) [only in this thread which is created on
the
fly].

So, I create a thread which makes the following thinks :

  • ruby_init
  • rb_eval_string(my script) [encapsulated in a rb_protect mechanism]
  • some rb_funcalls [encapsulated in a rb_protect mechanism]
  • ruby_finalize

And the thread is finished (and destoyed).

So, the first time I run my thread, all is perfect.
But, the second time, a segmentation fault occurs in the rb_eval_string
function. So, I suppose something wasn’t correctly cleaned by
ruby_finalize…

Is there another way to finalize the Ruby engine ? Is something missing
?

Thank you