From: Brent Roman Date: 2007-12-14T11:08:02+09:00 Subject: [PATCH] Continuations on dead threads crash ruby during GC This patch is against Ruby 1.8.6-p110 The bug appears in 1.8.6 and 1.6.8. Note: I have not yet verified whether this bug occurs in the 1.9 series. (It would be nice if someone tracking Ruby 1.9 development could help me there) Here is the 1.8.6 Changlog entry: Fri Dec 14 01:03:59 2007 Brent Roman * eval.c: fixes bug described in [ruby-core:13889] Added cc_mark for GC marking Continuations to prevent BLOCKs in use by those continuations from being prematurely freed when their parent thread dies Basically, we've got to prevent threads that are preserved in Continuations from being treated as "live" by the garbage collector if the thread referenced by that continuation has already died. There is nothing that can be done with such a "dead" Continuation, so its stack frames, etc. should be freed. Only the core Continuation object must be maintained as long as the script references it. Here is a test script that causes the crash until the attached patch is applied: http://www.nabble.com/file/p14328573/cont18.patch cont18.patch #!/usr/bin/env ruby #Crashes 1.8.6 & 1.6.8 as of Dec 13th, 2007 #submitted by brent@mbari.org def nestedThreadBug inner = nil outer = Thread.new(Thread.current) do |passedThread| $c4 = callcc {|c| c} inner = Thread.new passedThread do end end yield(outer) outer.value inner end (tries=100000).times { inner = nestedThreadBug do |thread| thread.value end inner.join } puts "Survived spawning #{tries} Threads with inner Continuations!!!" -- View this message in context: http://www.nabble.com/-PATCH--Continuations-on-dead-threads-crash-ruby-during-GC-tp14328573p14328573.html Sent from the ruby-core mailing list archive at Nabble.com.