From: Martin DeMello Date: 2005-04-09T05:29:40+09:00 Subject: Detecting thread exit immediately From the fxirb code: class FXIrb < FXText include Singleton include Responder attr_reader :input def FXIrb.init(p, tgt, sel, opts) unless @__instance__ Thread.critical = true begin @__instance__ ||= new(p, tgt, sel, opts) ensure Thread.critical = false end end return @__instance__ end def create super setFocus # IRB initialization @inputAdded = 0 @input = IO.pipe $DEFAULT_OUTPUT = self @im = FXIRBInputMethod.new @irb = Thread.new { IRB.start_in_fxirb(@im) #------------------------------ # INSERT CODE HERE #------------------------------ } end # ------------------------------------------------------------- I want to put something in INSERT CODE HERE that will call a method in the main thread when IRB.start_in_fxirb returns (i.e. just before the other thread dies), rather than having to wait for the GC to collect the the thread and then put in a check for @irb.alive?. Is there any good way to do this? (What I'm trying to do is have some way for the fxirb widget to notify the program containing it that the irb session has ended. Right now my choices seem to be to call exit (exits everything), to sleep(briefly) after I call @irb.run, and then check @irb.alive? (annnoying), to call GC.start everytime I call @irb.run and then check @irb.alive? (also annoying), or to have the thread itself notify something when it dies (but I can't quite think of how to do it).) martin