in the Multithreading Land

History of Ruby

Matz (Yukihiro Matsumoto) wanted a language perfect for his needs:

  • Syntactically Simple
  • Truly Object-Oriented
  • Having Iterators and Closures
  • Exception Handling
  • Garbage Collection
  • Portable

In the begining

Ruby 1.8 was released in 2003. This release made large amounts of changes to the agile 10-year-old language. Including:

  • Duck Typing (looks like a duck, swims like a duck, quacks like a duck: it’s a duck)
  • Fully Qualified Names (Foo::Bar)
  • Native YAML Support
  • WEBrick
  • StringIO
  • open-uri
  • PP (Pretty Printer for Hash#inspect)
  • ruby -run (UNIX commands for all! ruby -run -e mkdir foo)
  • And many other minor features

The Rebellious Teenager


In 2005, Ruby use took off. The reason: Ruby on Rails. This new framework changed the history of rapid web development. Ruby had been used in the past to write CGI scripts, but Ruby on Rails took this a step further. Rails has a Model-View-Controller structure that focuses on “convention over configuration”, which is great for developing web applications.

Title Text

Ruby 1.9

  • Significant speed improvements
  • New methods
  • New hash syntax ({ foo: 'bar' })
  • RubyGems included
  • New Socket API (IPv6 support)
  • Several random number generators
  • Regular Expression improvements
  • File loading performance improvements
  • Test::Unit Improvements
  • New encoding support
  • More string formatting tweaks
  • And so much more

Ruby 2.0

  • More speed improvements
  • Refinements (safe monkey patching)
  • Keyword arguments
  • UTF-8 by default
  • New regular expressions engine
  • Optimized garbage collection
  • The addition of built-in syntax documentation (ri ruby:syntax)
COLORS = { black:   "000",
           red:     "f00",
           green:   "0f0",
           yellow:  "ff0",
           blue:    "00f",
           magenta: "f0f",
           cyan:    "0ff",
           white:   "fff" }

class String
  COLORS.each do |color,code|
    define_method "in_#{color}" do
      "<span style=\"color: ##{code}\">#{self}</span>"
"Hello, World!".in_blue
 => "<span style=\"color: #00f\">Hello, World!</span>"


Global Interpreter Lock (GIL) is a mechanism used in computer language interpreters to synchronize the execution of threads so that only one thread can execute at a time. An interpreter which uses GIL will always allow exactly one thread to execute at a time, even if run on a multi-core processor


Applications running on implementations with a GIL can be designed to use separate processes to achieve full parallelism, as each process has its own interpreter and in turn has its own GIL. Otherwise, the GIL can be a significant barrier to parallelism—a price paid for having the dynamism of the language.[citation needed]


Threads & Fibers

Multithreading is mainly found in multitasking operating systems. Multithreading is a widespread programming and execution model that allows multiple threads to exist within the context of a single process. These threads share the process's resources, but are able to execute independently. The threaded programming model provides developers with a useful abstraction of concurrent execution.

A fiber is a unit of execution that must be manually scheduled by the application. Fibers run in the context of the threads that schedule them. Each thread can schedule multiple fibers. In general, fibers do not provide advantages over a well-designed multithreaded application.However, using fibers can make it easier to port applications that were designed to schedule their own threads.

EventMachine  &

EventMachine is an event-driven I/O and lightweight concurrency library for Ruby. It provides event-driven I/O using the Reactor pattern, much like JBoss NettyApache MINA, Python's TwistedNode.js, libevent and libev.

EventMachine is designed to simultaneously meet two key needs:

  • Extremely high scalability, performance and stability for the most demanding production environments.
  • An API that eliminates the complexities of high-performance threaded network programming, allowing engineers to concentrate on their application logic.


Much of the difficulty with building concurrent programs in Ruby arises because the object-oriented mechanisms for structuring code, such as classes and inheritance, are separate from the concurrency mechanisms, such as threads and locks. Celluloid combines these into a single structure, an active object running within a thread, called an "actor", or in Celluloid vernacular, a "cell".


JRuby is an implementation of the Ruby language using the JVM.

It aims to be a complete, correct and fast implementation of Ruby, at the same time as providing powerful new features such as concurrency without a global-interpreter-lock, true parallelism, and tight integration to the Java language to allow you to uses Java classes in your Ruby program and to allow JRuby to be embedded into a Java application.


Rubinius is a modern language platform that supports a number of programming languages.

Rubinius includes a bytecode virtual machine, generational garbage collector, and just-in-time (JIT) native machine code compiler. Rubinius provides concurrency support via native OS threads with no global interpreter lock.

The Feature

Modern concurrency tools for Ruby. Inspired by ErlangClojureScala,HaskellF#C#Java, and classic concurrency patterns.

The design goals of this gem are:

  • Be an 'unopinionated' toolbox that provides useful utilities without debating which is better or why
  • Remain free of external gem dependencies
  • Stay true to the spirit of the languages providing inspiration
  • But implement in a way that makes sense for Ruby
  • Keep the semantics as idiomatic Ruby as possible
  • Support features that make sense in Ruby
  • Exclude features that don't make sense in Ruby
  • Be small, lean, and loosely coupled