# Native threads in ruby

**URL:** <https://rubytalk.org/t/native-threads-in-ruby/43813>\
**Category:** ruby-talk\
**Created:** [16 January 2008 10:35 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813 "2008-01-16T10:35:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rick\_Penn](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@Rick\_Penn](https://rubytalk.org/u/Rick_Penn)\
**Post date:** [16 January 2008 10:35 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813/1 "2008-01-16T10:35:55Z")

</div>

Is there anyway possible, one can make use of native threads in Ruby?  
Maybe by interfacing with C or Java?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<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:** [16 January 2008 11:12 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813/2 "2008-01-16T11:12:32Z")

</div>

Rick Penn wrote:

> Is there anyway possible, one can make use of native threads in Ruby?  
> Maybe by interfacing with C or Java?

JRuby supports native threads today, where each Ruby thread maps to one native thread. There's also a second option, native thread pooling, where the number of native threads used is only ever as high as the number of threads running concurrently.

Normal native thread support is the default. Pooling can be enabled with a command-line option:

-J-Djruby.thread.pooling=true

- Charlie

---

<div class="post-metadata">

**Author:** ![Jason\_R](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Jason\_R](https://rubytalk.org/u/Jason_R)\
**Post date:** [16 January 2008 12:23 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813/3 "2008-01-16T12:23:45Z")

</div>

--enable-threading will put 1.8.6 in native thread mode, but it is unadvised  
to do so. Ruby 1.9 does uses native threads as well as a construct called  
Fibers, which I think are a better implementation of 1.8.6's green threads.

Jason

> **···**
>
> On Jan 16, 2008 6:12 AM, Charles Oliver Nutter \<charles.nutter@sun.com\> wrote:
> 
> > Rick Penn wrote:  
> > \> Is there anyway possible, one can make use of native threads in Ruby?  
> > \> Maybe by interfacing with C or Java?
> > 
> > JRuby supports native threads today, where each Ruby thread maps to one  
> > native thread. There's also a second option, native thread pooling,  
> > where the number of native threads used is only ever as high as the  
> > number of threads running concurrently.
> > 
> > Normal native thread support is the default. Pooling can be enabled with  
> > a command-line option:
> > 
> > -J-Djruby.thread.pooling=true
> > 
> > - Charlie

---

<div class="post-metadata">

**Author:** ![Tom\_M](https://avatars.discourse-cdn.com/v4/letter/t/839c29/32.png) [@Tom\_M](https://rubytalk.org/u/Tom_M)\
**Post date:** [16 January 2008 16:25 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813/4 "2008-01-16T16:25:36Z")

</div>

I believe that while 1.9 does support native threads, their benefit is  
minimal as there is a global interpreter lock most of the time. Is  
that correct?

> **···**
>
> On Jan 16, 7:23 am, Jason Roelofs \<jameskil...@gmail.com\> wrote:
> 
> > [Note: parts of this message were removed to make it a legal post.]
> > 
> > On Jan 16, 2008 6:12 AM, Charles Oliver Nutter \<charles.nut...@sun.com\> \> wrote:
> > 
> > \> Rick Penn wrote:  
> > \> \> Is there anyway possible, one can make use of native threads in Ruby?  
> > \> \> Maybe by interfacing with C or Java?
> > 
> > \> JRuby supports native threads today, where each Ruby thread maps to one  
> > \> native thread. There's also a second option, native thread pooling,  
> > \> where the number of native threads used is only ever as high as the  
> > \> number of threads running concurrently.
> > 
> > \> Normal native thread support is the default. Pooling can be enabled with  
> > \> a command-line option:
> > 
> > \> -J-Djruby.thread.pooling=true
> > 
> > \> - Charlie
> > 
> > --enable-threading will put 1.8.6 in native thread mode, but it is unadvised  
> > to do so. Ruby 1.9 does uses native threads as well as a construct called  
> > Fibers, which I think are a better implementation of 1.8.6's green threads.
> > 
> > Jason

---

<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:** [16 January 2008 19:03 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813/5 "2008-01-16T19:03:04Z")

</div>

Tom M wrote:

> I believe that while 1.9 does support native threads, their benefit is  
> minimal as there is a global interpreter lock most of the time. Is  
> that correct?

That is correct. Ruby 1.9 runs with native threads, but they don't run concurrently.

- Charlie

---

<div class="post-metadata">

**Author:** ![Rick\_Penn](https://avatars.discourse-cdn.com/v4/letter/r/e274bd/32.png) [@Rick\_Penn](https://rubytalk.org/u/Rick_Penn)\
**Post date:** [17 January 2008 01:18 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813/6 "2008-01-17T01:18:28Z")

</div>

It looks like I'll be using JRuby. Does JRuby have all the features that  
Ruby 1.8.6 has? Are there any plans to incorporate the features in 1.9  
to JRuby?

Thanks,  
Ryan

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<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:** [17 January 2008 10:32 UTC](https://rubytalk.org/t/native-threads-in-ruby/43813/7 "2008-01-17T10:32:57Z")

</div>

We've done the best job we can making JRuby compatible with Ruby 1.8.6, and hopefully others can attest to that. The only major feature missing is Continuations, which are a little sketchy with native threads anyway.

As for 1.9 features, we already have some. For example, we have a port of the regexp engine 1.9 uses, and a native-thread-backed implementation of Fibers. We probably won't include more before the JRuby 1.1 release later this month, but we'll add as many as possible after that, including all of 1.9's specific optimizations and support for abitrarily-encoded strings.

- Charlie

> **···**
>
> On Jan 16, 2008, at 19:18, Rick Penn \<emergence@gmail.com\> wrote:
> 
> > It looks like I'll be using JRuby. Does JRuby have all the features that  
> > Ruby 1.8.6 has? Are there any plans to incorporate the features in 1.9  
> > to JRuby?
> > 
> > Thanks,  
> > Ryan  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
