Chapter 13. Threads in Ruby

He draweth out the thread of his argument finer than the staple of his verbosity

William Shakespeare, Love’s Labours Lost, Act V, Sc. 1

Threads are sometimes called lightweight processes. They are nothing more than a way to achieve concurrency without all the overhead of switching tasks at the operating system level. (Of course, the computing community is not in perfect agreement about the definition of threads, but we won’t go into that.)

Ruby threads are user-level threads and are operating system independent. They work on DOS as well as on UNIX. There will definitely be a performance hit, however, which also varies by operating system.

Threads are useful in circumstances where, for instance, separate pieces of ...

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.