Hi Charles!

Sorry for the late response.

As others have noted, in this snippet, #apply is called on a sequential queue 
(queues created by Queue.new are always sequential), therefore there shouldn't 
be any problem here. If the queue was concurrent, however, there would be a 
thread safety issue.

I think this rdoc snippet should be rewritten to avoid confusion.

I see that you're wrapping a GCD-like interface in JRuby, it's very cool! I 
assume you want your interface to be cross platform, but in the case of JRuby 
running on Mac OS X, maybe we can extract our code as a C extension, this way 
JRuby would use the "system" GCD. Maybe we can also work together on creating a 
good test/spec suite for the GCD interface, because it's currently lacking.

Laurent

On Jan 21, 2011, at 9:57 PM, Charles Oliver Nutter wrote:

> I'm curious about this example in Queue#apply's rdoc:
> 
> *     gcdq = Dispatch::Queue.new('doc')
> *     @result = []
> *     gcdq.apply(5) {|i| @result[i] = i*i }
> *     p @result  #=> [0, 1, 4, 9, 16, 25]
> 
> apply is said to issue the jobs in parallel, so this would be making
> concurrent updates to the @result array. Are simple arrays in MacRuby
> thread-safe?
> 
> - Charlie
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel@lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

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

Reply via email to