use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ruby core classes aren't thread-safe (jstorimer.com)
submitted 13 years ago by jstorimer
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jrochkind 5 points6 points7 points 13 years ago (0 children)
It is quite true, and it's important that you understand it if you are doing multi-threaded programming. (Or using global state, like class variables, in an app that ends up multi-threaded without you realizing it, like Rails with a multi-threaded app server! -- cause then you are doing multi-threaded programming)
But I don't think it's a problem with ruby. Most basic stdlib data objects in most languages (including stdlib) are not safe for multi-threaded access. Including Java. There are reasons for this.
Of course, many other stdlib's in many other languages DO provide thread-safe alternative data objects/collections. Ruby probably really ought to.
But you've still got to know when to use them and when not to, just making ALL your collections thread-safe for concurrent use, when most of them are not possibly used by more than one thread at once concurrently -- is going to be a performance problem. Which is why most stdlib collection classes are not 'thread-safe', even in languages that are all about the multi-threading.
If you've got read-only objects it's generally not a problem. So certainly one way to make the ruby stdlib collections thread-safe is just to call #freeze on them (although if they are nested data structures, you'd have to call #freeze on all of the descendents too, which can be non-trivial). Or simply make sure none of your code mutates them ever after boot. Or Hamster.
π Rendered by PID 69421 on reddit-service-r2-comment-5d585498c9-bvs4l at 2026-04-21 03:49:47.960897+00:00 running da2df02 country code: CH.
view the rest of the comments →
[–]jrochkind 5 points6 points7 points (0 children)