Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ruby multithread
Concurrent Programming and Threads in Ruby - a reading list
02 April 2013
Many rubyists consider threads in Ruby as somewhat of an arcane knowledge, though in reality they’re a very well researched and understood concept. Of course, writing effective multithreaded concurrent programs requires certain amount of knowledge and discipline from the programmer, but there’s nothing that a smart one can’t learn if he wants to.
To help with the task, awesome @brainopia compiled a list of recommended reading on the topic of concurrency and threads. All kudos go to @brainopia, and the original list in Russian as available as a gist here:
Following is the translation of that list in English, for all my non-Russian-speaking friends.
1. Basics
First things first – the basic concepts and terminology. Don’t be afraid of the book on an unknown OS – it describes the basics extremely well, and the underlying concepts are the same in every OS and every language.
Getting Started with QNX Neutrino – Processes and Threads
You should read it at least until “Starting a process” part, and if you’re not afraid of C and want to know more about low-level workings of threads, POSIX system calls etc – keep reading until the end.
When you’re done with this part, you should understand what is a process, thread, mutex, priorites, semaphores, scheduler, contex-switch, kernel states.
2. Ruby – Threads and Fibers
Now, let’s dig into Ruby-specific things.
Overview of threads API in Ruby: TutorialsPoint – Ruby Multithreading
Basic summary of Green Threads (Ruby 1.8) and GIL (Global Interpreter Lock, Ruby 1.9): Leonardo Borges – Understanding Ruby Threads
More about GIL: – The Ruby Global Interpreter Lock
With the new knowledge handy, let’s look into the different implementations of threads in various popular (and less so) versions of Ruby: Engine Yard Developer Blog – Ruby, Concurrency and You
Adding fibers and CPU/IO-bound threads into the pot: Engine Yard Developer Blog – Concurrency, Real and Imagined, in MRI; Threads
And more on fibers: Paul Barry – Fibers in Ruby 1.9
A practical example of using fibers in Ruby: Dave Thomas – Pipelines Using Fibers in Ruby 1.9
And how one can emulate fibers with threads, for Ruby 1.8:
3. Event Loops
Event loops are all the rage these days, so you can’t miss this topic.
Essential knowledge on event loops: Engine Yard Developer Blog – What Are Events, Why Might You Care, and How Can EventMachine Help? Practicing Ruby – Event loop demystifed
Untangling event callbacks, and writing maintanable evented code: Ilya Grigorik – Untangling Evented Code with Ruby Fibers Dotan Nahum – Pragmatic Concurrency With Ruby
4. Videos
And to finish it off, some great talks on the topic of synchronisation and concurrency: Mike Perham @ RubyConf 2011 – Scaling Ruby with Actors, or How I Learned to Stop Worrying and Love Threads Jose Valim @ Rocky Mountain Ruby 2012
And on Celluloid (concurrent programming framework) and Sidekiq (efficient messaging): Tony Arcieri @ RubyConf 2012 – The Celluloid Ecosystem Mike Perham @ RubyConf 2012 – Asynchronous Processing for Fun and Profit
And that’s all – now go and write something awesome!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.