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 ?
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.
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 ?
···
On Apr 2, 2005 11:59 PM, Yogesh Sharma <ysharma@catprosystems.com> wrote:
Thanks for perfect answer and pointers to Lua and Tcl.
Yogesh
gga wrote:
···
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.