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
Hi, it looks like the variable's scope issue. I don't know detail why this crash happen yet. for workaround, you could use variable $array or @array instead of array. Thanks, 2012/1/13 Alan Skipp <al_skipp@fastmail.fm>:
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 _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Thanks for the quick response. I'll use your suggested workaround for now. All the best, Al On 13 Jan 2012, at 14:12, Watson wrote:
Hi,
it looks like the variable's scope issue. I don't know detail why this crash happen yet.
for workaround, you could use variable $array or @array instead of array.
Thanks,
2012/1/13 Alan Skipp <al_skipp@fastmail.fm>:
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 _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (2)
-
Alan Skipp
-
Watson