[MacRuby-devel] [MacRuby] #447: GCD Crashes
John Shea
johnmacshea at gmail.com
Mon Nov 23 01:03:30 PST 2009
Hi Pete,
I imagine that this bug is similar to one I posted (420). I was getting
similar behaviour and things much improved when I unrolled the loop. Maybe
you could try that? (or try what i suggest below).
I am waiting with bated breath to see Laurent's GCD code in the macruby
version of Sinatra.
I imagine that it is actually quite hard to turn ruby blocks into C blocks -
normally everything would be copied to the stack with C blocks - unless
manually copied to the heap - but probably in macruby they have to be
immediately copied to the heap. And then what to do with all the scoped (but
in C static) variables? In C there are complicated inferred return block
types which sometimes work, automatic releases sometimes, sometimes manual
releases are necessary of queues (i.e GCD does not use GC) - it all seems
rather complicated.
There is a note somewhere I believe in the macruby gcd code about how it
might be bad to access instance variables from a queue - none the less when
using Laurent's web_server.rb code as model - the threading bit - and doing
something similar in GCD - I got something working ok.
Using threads (as per the example) and GCD I could get some speed
improvements - however on a 2 core machine - those improvements were not
much - i actually don't expect that much on only 2 cores - since there is a
hell of a lot of other threading happening (eg GC) even if we don't consider
the demands that the rest of the OS is putting on the processor.
So with 2 cores I found best results to limit to two GCD serial queues.
cpuCount = NSProcessInfo.processInfo.processorCount
is a helpful command in this regard.
I would be very interested to see your results if you try this out. One
thing to watch out for variable allocations within the queue block - the
variables might not be instantly available (like the next line).
>From what i have read there are many resources in the OS which can stall
when there are too many processes trying to access them - so perhaps a good
way in the future is actually to wrap all resource access in semaphores -
adjusted by cpu count.
Cheers,
J
On Mon, Nov 23, 2009 at 1:27 AM, MacRuby <ruby-noreply at macosforge.org>wrote:
> #447: GCD Crashes
>
> ------------------------------+---------------------------------------------
> Reporter: pete@… | Owner: lsansonetti@…
> Type: defect | Status: new
> Priority: major | Milestone: MacRuby 0.5
> Component: MacRuby | Keywords:
>
> ------------------------------+---------------------------------------------
> I've been playing with the GCD support in 0.5, and I can get it to
> misbehave consistently with a fairly simple script (attached.)
>
> Various things happen when this script is run. Sometimes I get a crash
> with the assertion below, sometimes I get a seg fault.
>
> Assertion failed: ((arity.max == -1) | | (argc <= arity.max)), function
> !__rb_vm_fix_args, file dispatcher.cpp, line 29.
>
> Sometimes it runs mostly ok, but spits out NaN instead of the correct
> value at random intervals.
>
> Something to do with the block being prematurely garbage collected
> perhaps?
>
> --
> Ticket URL: <http://www.macruby.org/trac/ticket/447>
> MacRuby <http://macruby.org/>
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20091123/4e0a0a45/attachment.html>
More information about the MacRuby-devel
mailing list