# Accessing ruby 1.9 interpreter from other threads

**URL:** <https://rubytalk.org/t/accessing-ruby-1-9-interpreter-from-other-threads/40224>\
**Category:** ruby-talk\
**Created:** [29 August 2007 07:19 UTC](https://rubytalk.org/t/accessing-ruby-1-9-interpreter-from-other-threads/40224 "2007-08-29T07:19:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada1](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@Nobuyoshi\_Nakada1](https://rubytalk.org/u/Nobuyoshi_Nakada1)\
**Post date:** [29 August 2007 07:19 UTC](https://rubytalk.org/t/accessing-ruby-1-9-interpreter-from-other-threads/40224/1 "2007-08-29T07:19:34Z")

</div>

Hi,

At Tue, 28 Aug 2007 19:33:02 +0900,  
Bill Kelly wrote in [ruby-talk:266532]:

> I seem to recall hearing 1.9 is using native threads now.
> 
> If so, does that mean it's now safe for multiple OS threads  
> to call into the 1.9 ruby interpreter, and eval or execute  
> ruby code? (I'm assuming some sort of interpreter lock would  
> need to be grabbed.)

And to bind calling native thread a ruby thread. But still not  
provided now.

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [29 August 2007 10:16 UTC](https://rubytalk.org/t/accessing-ruby-1-9-interpreter-from-other-threads/40224/2 "2007-08-29T10:16:00Z")

</div>

Nobuyoshi Nakada wrote:

> Hi,
> 
> At Tue, 28 Aug 2007 19:33:02 +0900,  
> Bill Kelly wrote in [ruby-talk:266532]:
> 
> > I seem to recall hearing 1.9 is using native threads now.
> > 
> > If so, does that mean it's now safe for multiple OS threads  
> > to call into the 1.9 ruby interpreter, and eval or execute  
> > ruby code? (I'm assuming some sort of interpreter lock would  
> > need to be grabbed.)
> 
> And to bind calling native thread a ruby thread. But still not  
> provided now.

A similar mechanism is used in JRuby to "adopt" incoming Java threads as Ruby threads, allowing them to participate in thread events like kill and raise. But there's nothing explicit about it; threads that haven't been adopted are adopted automatically. Can't this be done automatically?

- Charlie

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada1](https://avatars.discourse-cdn.com/v4/letter/n/9f8e36/32.png) [@Nobuyoshi\_Nakada1](https://rubytalk.org/u/Nobuyoshi_Nakada1)\
**Post date:** [5 September 2007 07:28 UTC](https://rubytalk.org/t/accessing-ruby-1-9-interpreter-from-other-threads/40224/3 "2007-09-05T07:28:38Z")

</div>

Hi,

At Wed, 29 Aug 2007 19:16:00 +0900,  
Charles Oliver Nutter wrote in [ruby-talk:266657]:

> A similar mechanism is used in JRuby to "adopt" incoming Java threads as  
> Ruby threads, allowing them to participate in thread events like kill  
> and raise. But there's nothing explicit about it; threads that haven't  
> been adopted are adopted automatically. Can't this be done automatically?

Does that "adopt" occur in any call to ruby? Isn't it  
performance overhead?

> **···**
>
> --  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [5 September 2007 18:43 UTC](https://rubytalk.org/t/accessing-ruby-1-9-interpreter-from-other-threads/40224/4 "2007-09-05T18:43:27Z")

</div>

Nobuyoshi Nakada wrote:

> Hi,
> 
> At Wed, 29 Aug 2007 19:16:00 +0900,  
> Charles Oliver Nutter wrote in [ruby-talk:266657]:
> 
> > A similar mechanism is used in JRuby to "adopt" incoming Java threads as Ruby threads, allowing them to participate in thread events like kill and raise. But there's nothing explicit about it; threads that haven't been adopted are adopted automatically. Can't this be done automatically?
> 
> Does that "adopt" occur in any call to ruby? Isn't it  
> performance overhead?

Not really, if the thread hasn't been adopted it just constructs a new Ruby thread to wrap it and a "thread context" to govern frames, scopes, etc for Ruby execution. That's a one-time hit that only happens the first time a normal Java thread enters Ruby code. From then on it largely just looks like any other Ruby thread.

- Charlie
