#597: Dispatch Queue async method inconsistent results
--------------------------------------+-------------------------------------
Reporter: knut.olaf.l...@… | Owner: ernest.prabha...@…
Type: defect | Status: closed
Priority: blocker | Milestone:
Component: MacRuby | Resolution: invalid
Keywords: GCD async method |
--------------------------------------+-------------------------------------
Changes (by ernest.prabha...@…):
* 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/>
_______________________________________________
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel