On Jan 24, 2011, at 8:00 AM, Alan Skipp wrote:

> The post was admittedly vague, but was more of an idea about a general 
> purpose thread safe array class (in principle, this could apply to any 
> mutable class). Perhaps implemented as a module that would redirect all 
> method calls through a serial dispatch queue. This would mean that the array 
> (or other mutable collection) could be mutated from multiple threads/queues 
> without fear of bad things happening.

FWIW, we've tried this same approach experimentally (use a per-object serial 
queue behind the scenes to implement an async setter / sync getter model) over 
in CoreFoundation land, and it seemed to work reasonably well for the most 
part.  We ran into some compatibility issues with a few of the methods which 
just didn't lend themselves to a thread-safe object model, enough that we 
couldn't simply do this as a completely transparent solution, but it mostly 
Just Worked and I think MacRuby (or, for that matter, JRuby) could do something 
very similar and probably get away with it since Ruby arrays/hashes/strings 
aren't quite so inclined to hand pointers to their internal state around to 
clients of the API.   Laurent doesn't exactly agree with me since he's still 
focused on performance, but I think it should definitely be possible to declare 
a Ruby object as "contended" in some way such that everything then goes through 
a serial queue implicitly to access it - I'm not saying this sh
 ould be true for every object, just the ones for which you need thread safety.

- Jordan

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to