[MacRuby-devel] macruby GCD bug?
Alan Skipp
al_skipp at fastmail.fm
Fri Jan 13 05:04:27 PST 2012
I've been continuing with my efforts to implement Fibers using GCD and in the process I think I may have uncovered a Macruby bug - though perhaps it's a bug in my code? Is there anything fundamentally wrong with the code posted below? It consistently results in a EXC_BAD_ACCESS error.
Cheers,
Al
class Fiber
def initialize &block
@block = block
@yield_sem = Dispatch::Semaphore.new(0)
@resume_sem = Dispatch::Semaphore.new(0)
@fiber_queue = Dispatch::Queue.new "fiber"
@fiber_queue.async {@yield_sem.wait} # immediately suspend @fiber_queue
# the following block will only run after '@yield_sem' is signalled – which happens when 'resume' is called
@fiber_queue.async do
@block.call
@resume_sem.signal # the block has finished - let the caller resume
end
end
def resume
@yield_sem.signal
@resume_sem.wait # causes the GCD queue of the caller to suspend
end
end
array = [1,2,3]
fiber = Fiber.new { array << 4 } # crash when fiber is resumed
fiber.resume
p array # we don't get this far
More information about the MacRuby-devel
mailing list