[MacRuby-devel] [MacRuby] #597: Dispatch Queue async method inconsistent results
MacRuby
ruby-noreply at macosforge.org
Wed Feb 3 11:45:43 PST 2010
#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 |
--------------------------------------+-------------------------------------
Comment(by lsansonetti@…):
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/>
More information about the MacRuby-devel
mailing list