~/talk

Look out! Gotchas of Using Threads in Ruby

Talkat Euruko 2023 · 2023-09-21..09-23· [ruby, concurrency]
slides:none on file

Ruby MRI threads are concurrent but not parallel so CPU work doesn’t speed up while JRuby/truffle and ractors can run in parallel, and naive shared mutable state produces real errors like 11 extra elements in a counter example. Practical fixes: use thread coordination with Queue or join, protect initialization with a shared Mutex around the assignment, prefer Concurrent::Map or Atomic classes from concurrent-ruby, freeze or copy shared data, and avoid sleeps in tests—use waiter loops or rspec-wait.

AI-written summary · about

  1. 0:00Thread gotchas in Ruby
  2. 2:18Why concurrency matters
  3. 4:22Concurrency models in Ruby
  4. 9:40Threads concurrent not parallel
  5. 12:13Parallelism in JRuby TruffleRuby
  6. 13:38Avoid sleeps in tests
  7. 18:31Hash iteration risks
  8. 23:27Atomic behavior explained
  9. 29:52Heisenbugs in Ruby code
  10. 30:36Non-atomic initialization
  11. 34:09Sharing mutable state
  12. 35:35Lazy loading in threads
  13. 36:38Thread safety recap
  14. 38:26Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.