[MacRuby-devel] some gcd issues
B. Ohr
jazzbox at 7zz.de
Fri Jun 4 01:28:35 PDT 2010
Hi,
yesterday I did my first steps with GCD: parsing a very big CSV-file, processing and filtering it and displaying the result in a table view. Before GCD the UI was blocked for more than a minute, now the user can continue working instantly. Hey that’s really, really great!
There are some issues I don’t understand:
1. @job.group.notify(Dispatch::Queue.main) {} # gives an error...
@job.group.notify(Dispatch::Queue.concurrent) {} # …..while is working
2. @job.group.notify(Dispatch::Queue.concurrent) {} # the block is called twice or more times
3. the proxy object does not work here (I’m not sure, that I am using it correctly)
I made a small Xcode project demo out my project and attached it to this mail. (you can multi-click on the job button)
- Bernd
######
require 'dispatch'
class AppController
attr_accessor :calculations, :running
def initialize
self.calculations = []
@prefix = 1
@job = Dispatch::Job.new
#the main queue is used here because the UI is bound to the calculations array
@calc_queue = Dispatch::Queue.main
end
def calc_sync &block
@calc_queue.async { block.call }
end
def nextPrefix
prefix = @prefix
@prefix += 1
prefix
end
def calc1
# @calc_proxy = Dispatch::Proxy.new(self.calculations, at job.group, at calc_queue)
@job.add do
prefix = nextPrefix
10.times do |i|
dur = rand / 4 + 0.2
sleep(dur)
c = Calculation.new("#{prefix}:#{i}",dur)
calc_sync { self.calculations += [c] }
# proxy does not work here:
# @calc_proxy += [c]
end
#NSLog self.calculations.inspect
end
# why can the notify block be called twice ore more?
# if true
if !running
self.running = true
# notifying on the main queue is crashing here:
# @job.group.notify(@calc_queue) { NSLog "notify“; self.running = false }
@job.group.notify(Dispatch::Queue.concurrent) { NSLog "notify"; self.running = false }
end
end
def jobAction sender
calc1
end
def clearAction sender
self.calculations = []
end
end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcd_demo.zip
Type: application/zip
Size: 28576 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100604/c27990dd/attachment-0001.zip>
-------------- next part --------------
More information about the MacRuby-devel
mailing list