[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Embedding Ruby Interpretor in threaded C / C++

Yogesh Sharma

4/2/2005 6:27:00 PM

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
4 Answers

Shajith

4/2/2005 7:04:00 PM

0

On Apr 2, 2005 11:59 PM, Yogesh Sharma <ysharma@catprosystems.com> wrote:
> 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'm not sure I read you, but try this:
http://metaeditor.sourceforge....

HTH!
Shajith


Yogesh Sharma

4/2/2005 8:18:00 PM

0

Shajith wrote:
> On Apr 2, 2005 11:59 PM, Yogesh Sharma <ysharma@catprosystems.com> wrote:
>
>
> I'm not sure I read you, but try this:
> http://metaeditor.sourceforge....
>
> HTH!
> Shajith
>
>
Thanks for link which answered first part.

Other half:

Extract from http://www.linuxjournal.com/ar...:
"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 ?

gga

4/2/2005 8:52:00 PM

0

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.

Yogesh Sharma

4/3/2005 2:33:00 PM

0

Hi gga,

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.
>