File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ruby and the fly likes How does Ruby do concurrency? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "How does Ruby do concurrency?" Watch "How does Ruby do concurrency?" New topic

How does Ruby do concurrency?

Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Or perhaps, how should one do concurrency in Ruby? I've read several articles about Ruby and concurrency and I'm not sure I understand.

This article sez there is no such thing as concurrency in Ruby.

This article and this article approach it as special add-on.

Meanwhile Ruby tutorials explain a system of threading that reminds me of java concurrency circa 1.4.

Razvan Popovici

Joined: Feb 15, 2007
Posts: 14
So why is the concurrency in Java 1.4 different of the concurrency in Java 7 (except of a deprecated thread kill function)?
There are two points in concurrency: one is the capability of spawning threads; as opposite to the processes, they share the memory with the parent thread. Processes may share some areas of memory, named shared memory, but this is not implemented in Java either. Second is the synchronization: the ability of a thread to wait for an event caused by another thread (such as signaling, closure, release of a resource), semaphores and critical sections.
It would be great if the author would address these two topics.
David Black

Joined: Aug 16, 2009
Posts: 13
Hi --

Threading is a bit of a moving target in Ruby, especially as between 1.8 and 1.9, and between MRI (Matz's Ruby Interpreter, the original/canonical version) and other implementations, JRuby in particular. JRuby makes use of Java threads, so it can do whatever Java can do, thread-wise. Ruby 1.8 had pure green threads; the whole thread system was written entirely in the interpreter, with no dependence on any underlying OS components. In 1.9, the basic 1.8 thread functionality is there, and there's also support for OS threads if they're present.

The topic that seems to come up the most with regard to Ruby threads recently is the "global VM lock" or "global interpreter lock", which is present in the 1.9 threading model and which, as I understand it, severely restricts true concurrency, because everything has to wait until that one big lock is available. If you want more info on this, and on the work that's going on toward true concurrency, here's an interview with Koichi Sasada, the main architect of YARV, the 1.9 VM.


Ruby training coming up in September! David A. Black and Erik Kastner team up for fast-paced, four-day Ruby intro, in New Jersey, September 14-17. See or contact David.
I agree. Here's the link:
subject: How does Ruby do concurrency?
It's not a secret anymore!