Dillon Benson
Dillon Benson

Reputation: 4440

Ruby threads not good enough?

How is that JRuby's support for multithreading is any better than regular Ruby's support for it? What's wrong with threads in plain old Ruby?

Upvotes: 1

Views: 116

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84114

"Normal" ruby (or mri) has a great big lock that prevents more than one thread from running ruby code at a time (known as the GIL or GVL).

Rubinius and jruby don't have this lock. In ruby 1.8.x the threads were green threads too, but as of ruby 1.9 ruby threads are mapped to native threads. The GVL stops you from gaining much benefit though.

Native extensions can run code outside of the lock so that, for example, multiple MySQL queries can run simultaneously from different threads but they can't call into the regular ruby api when they don't hold the lock

Upvotes: 2

Related Questions