From: Chuck Remes Date: 2010-09-15T13:07:10+09:00 Subject: Re: Ruby Multi-threading? On Sep 14, 2010, at 10:59 PM, Terry Michaels wrote: > I read a Ruby e-book recently that indicated that although Ruby has > Multi-threading capabilities, it is a fake multi-threading. I.e., the > interpreter simply switches between the executing threads, rather than > running them concurrently. > > Then recently I came across an online Ruby tutorial that specifically > said that Ruby threads could be executed in parallel on a multi-core > machine. So I'm a little confused. > > Does Ruby have real multi-threading, or is it just context switching? > This is a rather important issue for me. Just about any book on this topic will have outdated information. Here's the breakdown. MRI 1.8.x Green threads (the "fake" multithreading you mentioned above) that map to a single process thread. MRI 1.9.x Native threads. However, most processing is single-threaded because the runtime has a GIL (Global Interpreter Lock) that prevents a lot of concurrency. Each revision of 1.9.x makes the lock more granular for better concurrency. JRuby 1.5.x and later No GIL. Native threads. All the concurrency you could possibly want. Rubinius 1.0.1 and 1.1 (forthcoming) Contains a GIL and many of the same limitations as 1.9.x. However, a new development branch (hydra) aims to remove the GIL in a near future release. There will still be locks but they will be much more granular. IronRuby Not sure. Maglev Not sure. The point of the above is that the picture is constantly changing and each runtime has different characteristics. Have fun exploring. cr