small medium large xlarge

Seven Concurrency Models in Seven Weeks; Working with Ruby Threads

September 25, 2013

On this day in 1906, Leonardo Quevedo demonstrated a radio-controlled robot that drove a boat around the harbor. Remote control was easier back then, as there was only one remote-controlled robot in all the world. But once you get thousands or millions of them trying to work together and cooperate, the game gets a lot tougher.

And that's where we are now: facing new challenges trying to work with thousands or millions of processes across multiple cores, handling thousands of users and terabytes of data, with little to no down time. For new challenges, you need new techniques: Seven Concurrency Models in Seven Weeks: When Threads Unravel, now in beta from

For a more introductory look at threads, and specifically in a Ruby or Ruby on Rails environment, start with Working with Ruby Threads, now available from

After all, if you don't threading understand results different may get unexpected you ;)

Seven Concurrency Models in Seven Weeks: When Threads Unravel

This book will show you how to exploit different parallel architectures to improve your code's performance, scalability, and resilience.

Learn about the perils of traditional threads-and-locks programming and how to overcome them through careful design and by working with the standard library. See how actors enable software running on geographically distributed computers to collaborate, handle failure, and create systems that stay up 24/7/365. Understand why shared mutable state is the enemy of robust concurrent code, and see how functional programming together with technologies such as Software Transactional Memory (STM) and automatic parallelism help you tame it.

You'll learn about the untapped potential within every GPU and how GPGPU software can unleash it. You'll see how to use MapReduce to harness massive clusters to solve previously intractable problems, and how, in concert with Stream Processing, big data can be tamed.

With an understanding of the strengths and weaknesses of each of the different models and hardware architectures, you'll be empowered to tackle any problem with confidence.

Now available in beta from

Working with Ruby Threads

Working with Ruby Threads starts with an introduction to how threading works at a high level, showing you what your Ruby programs look like with multiple threads at play. You'll learn about things such as context switching and race conditions.

From there, you'll get a safari tour of Ruby's Thread API, followed by a deep dive into the infamous GIL: its effects, its implementation, and the reason it's there. Next you'll look at JRuby and Rubinius, how they don't have a GIL, and how this affects multi-threaded code when run on those implementations.

The middle section of the book is all about thread safety: what it means, what it looks like, how to write thread-safe code, how to recognize thread-dangerous code, and what options Ruby provides for writing correct concurrent programs. You'll then look at abstractions on top of threads (such as Actors), and wrap up by walking through some real-world, multi-threaded code. You'll get to see examples from the Puma web server, and one from the Celluloid-based Sidekiq project, bit by bit with explanations along the way. Two appendices take you into advanced topics such as immutability and compare-and-swap operations.

After all this, you'll have a good handle on multi-threaded concurrency, and you won't be afraid to apply it to your next Ruby project.

Now available from

Did You Know?

We're moving away from OpenID. If you're currently using OpenID to login to, please set a password with us directly instead. We'll be turning off OpenID support on January 1st, 2014. Thanks!

Upcoming Author Appearances

  • 2013-09-26 Chris Adamson, CocoaConf Columbus
  • 2013-09-27 Jesse Anderson, ISVCON 2013 – Reno
  • 2013-09-27 Jonathan Penn, CocoaConf Columbus
  • 2013-09-27 Jonathan Penn, CocoaConf Columbus
  • 2013-09-27 Chad Fowler, Amsterdam, Netherlands
  • 2013-09-27 Chris Adamson, CocoaConf Columbus
  • 2013-09-28 Chris Adamson, CocoaConf Columbus
  • 2013-09-30 Chad Fowler, Aarhus, Denmark
  • 2013-10-01 Johanna Rothman, StarWest, Anaheim, CA
  • 2013-10-02 Johanna Rothman, AgileSoCal, Irvine, CA
  • 2013-10-03 Jesse Storimer, Unix fu Workshop, Online
  • 2013-10-04 Chris Strom, NationJS, Washington DC
  • 2013-10-04 John M Athayde, NationJS
  • 2013-10-09 Chad Fowler, Tel Aviv, Israel
  • 2013-10-09 Johanna Rothman, PMI Exchange, College Station, TX
  • 2013-10-09 Johanna Rothman, PMI Exchange, College Station, TX
  • 2013-10-12 Jonathan Penn, CocoaSlopes (Ogden, Utah)
  • Don't Get Left Out

    Are your friends jealous that you get these spiffy email newsletters and they don't? Clue them in that all they need to do is create an account on (email address and password is all it takes) and select the checkbox to receive newsletters.

    Are you following us on Twitter and/or Facebook? Here's where you can find us and keep up with the latest news and commentary, and occasional discounts:

    Tell your friends! Tweet this Follow us on Twitter: @pragprog, @pragpub, Andy @PragmaticAndy and Dave @pragdave.

    Coming Soon:

    • Agile Web Development with Rails 4 (in print)
    • Programming Erlang, 2nd Ed (in print)
    • The Dream Team Nightmare: An Agile Adventure
    • iPad and iPhone Kung Fu

    Recently Released:

    Thanks for your continued support,

    Dave & Andy The Pragmatic Programmers

    Books • eBooks • PragPub Magazine • Audiobooks and Screencasts