13.3. Conclusion

As we’ve seen here, Ruby has so-called green threads (not native threads). These do not benefit from having multiple processors in a machine, but they can still be used for some level of concurrency. Threads can be a useful technique in many circumstances, but they can be somewhat problematic to code and debug. This is particularly true when we use sophisticated synchronization methods to achieve correct results.

Ruby provides classes such as Mutex, Monitor, and ConditionVariable to aid in synchronization. It also provides the built-in Queue and SizedQueue classes, which are thread-safe.

In Chapter 14, “Scripting and System Administration,” we move away from a discussion of programming technique in itself to a more task-oriented ...

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.