#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 | --------------------------------------+-------------------------------------
Comment(by lsansone...@…): Ernie's diagnosis is wrong. The problem here is that the program is accessing the result variable concurrently. Accesses must be synchronized by using a serial queue. The following should work (untested) {{{ def fib(n=1) if n < 3 1 else fib(n-1) + fib(n-2) end end q = Dispatch::Queue.concurrent grp = Dispatch::Group.new syncq = Dispatch::Queue.new('sync') result = [] 8.times do |index| q.async(grp) do res = fib(ARGV[0].to_i) syncq.sync { result[index] = res } end end }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/597#comment:4> MacRuby <http://macruby.org/> _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel