Embedding Ruby Interpretor in threaded C / C++

Y

Yogesh Sharma

Hi,

Can someone please point me to documentation for embeding Ruby
interpretor in C / C++ (C++ Prefered).

What is the best way do embed Ruby interepretor in C/C++ threaded
program. So that each thread can execute its own assigned set of script.

I have seen that Python doesn't allows this kind of setup. It create a
Global lock and even C/C++ is threaded scripts are executed in python's
thread control. Is it same in Ruby also ?

Thanks,
Yogesh
 
Y

Yogesh Sharma

Shajith said:
I'm not sure I read you, but try this:
http://metaeditor.sourceforge.net/embed/

HTH!
Shajith
Thanks for link which answered first part.

Other half:

Extract from http://www.linuxjournal.com/article/3641:
"In order to support multi-threading, Python uses a mutex to serialize
access to its internal data structures. I will refer to this mutex as
the ``global interpreter lock''. Before a given thread can make use of
the Python C API, it must hold the global interpreter lock. This avoids
race conditions that could lead to corruption of the interpreter state."

Is there anything like `global interpreter lock' in Ruby also ?
 
G

gga

Hi, Yogesh. In ruby this is a tad worse, as there's basically no lock
of any kind so you can run into all sorts of race conditions. You can
obviously do what python does by providing your own lock before you
eval any ruby code, but I agree this is far from ideal.
There's also always only a single instance of the ruby interpreter
(which cannot even be re-inited, unlike python), so all your scripts
will share their global variables.
These are limitations of the current ruby interpreter and not of the
language. The ruby interpreter is being rewritten to address these
problems, but don't expect anything any time soon.

If you need to do any of the above today, I highly recommend you look
into either Lua or TCL, both of which can keep different interpreter
contexts easily. Lua is still somewhat new but it does have a
relatively similar syntax to Ruby (at least as long as you don't do
much OO programming, where their OO model is a tad too cumbersome
compared to ruby or python).
If newer languages scare you, TCL is a very mature language which was
built with embedding in mind and has hundreds of libraries all around.
However, its syntax of brackets is a tad arcane. TCL was never built
with the idea of classes or advanced constructs in mind, so its
performance in that area is usually less than some more modern
languages.
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top