#597: Dispatch Queue async method inconsistent results --------------------------------------+------------------------------------- Reporter: Knut.Olaf.Lien@… | Owner: ernest.prabhakar@… Type: defect | Status: closed Priority: blocker | Milestone: Component: MacRuby | Resolution: invalid Keywords: GCD async method | --------------------------------------+------------------------------------- Changes (by ernest.prabhakar@…): * status: new => closed * resolution: => invalid Comment: I even get it with no function at all. => [0, 1, 2, 3, false, 5] Oh, wait, you're using a *local* variable. You need to use a block variable, I think: @result = []; 8.times {|i| q.async(grp) {@result[i] = i}} p @result => [0, 1, 2, 3, 4, 5, 6, 7] Using a copy of the array "sometimes" works, but I'm not quite sure how or why. Still, the technical answer is that attempting to modify a dynamic object inside a GCD leads to "undefined" behavior, so I'll mark this as "behaves correctly". :-/ -- Ticket URL: <http://www.macruby.org/trac/ticket/597#comment:3> MacRuby <http://macruby.org/>