Re:Ruby core classes aren't thread safe
by zopticity on Monday February 25, 2013 @05:06PM
(#5282180)
Totally agreed. Why do I have to lock it myself (even on a high level language like Ruby)? I'm not programming for C!
[ Parent
| on HN ]
You only have to do it yourself once you decide to use threads.
And there is not really a way around that. If the language mandated that all primitive operations (for whatever reasonable operation of 'primitive') were atomic, most multi-threaded programs would slow down to a crawl.
Even ignoring that, having atomic primitives is not sufficient to prevent race conditions. Things like "if balance > withdrawal {balance -= withdrawal; ...} need larger ranges of locking, and no compiler is going to tell you how large they have to be.