Anton Garcia Dosil
Anton Garcia Dosil

Reputation: 299

Advantages of non-concurrent Ruby Threads in Ruby 1.9?

I have been reading about Ruby 1.9 Thread and I see that all ruby threads go through the Global Interpreter Lock (GIL for friends) and that concurrency is actually non-existant.

I have done a test (without any signals nor waiting) and the performance using threads doesn't only not improve but the operations actually take more time than running them serially

My question is basically - Whats the point for these Threads if they are not concurrent? Is there any hope that they will be concurrent in the future?

Upvotes: 4

Views: 145

Answers (2)

aceofbassgreg
aceofbassgreg

Reputation: 3937

Parallelism is nonexistent, but Ruby threads do not prevent concurrent execution of Ruby code. Even on a single core machine, concurrent code execution is possible. I think you just conflated the terms 'concurrent' and parallel'.

See Working with Ruby Threads by Jesse Storimer for more details.

Upvotes: 0

Ilya O.
Ilya O.

Reputation: 1500

A lot of other Ruby interpreters (JRuby, Rubinius) don't actually have GILs. Also, MRI 2.0 is going to do away with the GIL as well.

Also, in a lot of cases (such as when waiting for IO) the interpreter does switch to another thread. So while it's not technically multithreading (in the case of MRI/REE as of 1.9), it does get some of the benefits.

Upvotes: 3

Related Questions