From: Charles Oliver Nutter Date: 2008-12-24T07:27:42+09:00 Subject: Re: Are all Ruby built-in objects thread safe? Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Are all Ruby built-in objects thread safe?" > on Tue, 23 Dec 2008 18:21:27 +0900, "Just Another Victim of the Ambient Morality" writes: > > | Are all built-in objects thread safe? > > For MRI (1.8.x) and YARV (1.9.x), every C implemented methods are > protected by GIL (Global Interpreter Lock), so that you don't have to > worry about. But it might depend on each implementation. In JRuby we've made a best attempt to keep the core data structures like Array, Hash, and String as thread-safe as possible without introducing locks (which would slow down single-threaded cases). There are cases where when using Array or Hash you may get ConcurrencyErrors raised. This is the trade-off for having fast lock-free collections. I would very much welcome a set of guaranteed-thread-safe wrapper collections folks could use if they're concerned about concurrency, since it would be unreasonable to penalize all code with locking. For now, learn and love Mutex, or don't share collections across threads. - Charlie