[MacRuby-devel] thread-safety and collections in macruby

Matt Aimonetti mattaimonetti at gmail.com
Wed Oct 19 08:28:10 PDT 2011


The proper way to protect mutable objects is to use a mutex: http://www.ruby-doc.org/core-1.9.2/Mutex.html

- Matt

Sent from my iPhone

On Oct 19, 2011, at 8:06, Chuck Remes <cremes.devlist at mac.com> wrote:

> 
> On Oct 19, 2011, at 12:41 AM, Terry Moore wrote:
> 
>> If you're not wring/changing the array no problems. But to be safe use Object#freeze...
>> 
>> Terry Moore
>> 
>> On 19/10/2011, at 6:26 PM, Michael Johnston <lastobelus at mac.com> wrote:
>> 
>>> Note, in my example I can also guarantee that none of the elements in b are going to be changed (for example, an array of strings)
> 
> Object#freeze is a terrible method. Supporting it requires an extra check (#frozen?) in every method that tries to modify an object. This is why Ruby is slow (certainly not the only reason, but decisions like this are everywhere). 
> 
> :)
> 
> Using #freeze won't save you but it will throw a RuntimeException if you try to modify a frozen object. So it's really only good for pointing out that you have a bug when you attempt to modify your immutable array.
> 
> cr
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel


More information about the MacRuby-devel mailing list