Junior Track Roadmap

Ruby: threading basics

This course covers how Ruby threads behave once they are running. It shows how to read a thread's lifecycle with Thread#status and alive?, and how report_on_exception and abort_on_exception treat a thread that raises. It builds a deadlock from two mutexes locked in opposite order and shows it safely with join timeouts. It uses Queue and SizedQueue to pass work between threads with backpressure. Finally, it times the GVL with Benchmark.realtime: threads give a large speedup for I/O-bound work and almost none for CPU-bound work.

What you'll learn

  • ✓Reading a thread's lifecycle with Thread#status and alive?
  • ✓Handling thread exceptions with report_on_exception and abort_on_exception
  • ✓Reproducing a deadlock and avoiding it with consistent lock ordering
  • ✓Passing work between threads with Queue and SizedQueue
  • ✓Measuring the GVL with Benchmark.realtime for I/O-bound and CPU-bound work
Free preview · Lesson 1 3 min read

Thread#status and the thread lifecycle

The lesson "Threads and concurrency", in the intern course Operating system basics, covered process against thread and concurrency against parallelism. It also covered the GVL and why it's released during I/O, Thread.new/.join, a race-condition demo fixed with Mutex#synchronize, and Puma's model of…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...