From: Robert Klemme Date: 2009-05-14T20:37:49+09:00 Subject: Re: Monitor Error when Joining Threads 2009/5/14 Jeff Shantz : > I realize this is an old question, but I'm replying in case anyone else > encounters this error, since I just found the fix to it. > > You need to make a call to super() in your constructor. > > So, the following: > >> class StatsTracker < Monitor >>   include Singleton >>   ... >>   def foo >>     synchronize do >>       # do something >>     end >>   end >>   ... >> end > > should be changed to: > >  class StatsTracker < Monitor >  include Singleton > >   def initialize >     super() >   end > >   def foo >     synchronize do >       # do something >     end >   end >   ... >  end > > The same is true if you're using MonitorMixin.  For instance, > > class StatsTracker >  include Singleton >  include MonitorMixin > >   def initialize >     super() >   end > >   def foo >     synchronize do >       # do something >     end >   end >   ... >  end > > Hope that helps someone. Just an additional note: the reason why the exception appears to come out of Thread.join is this: irb(main):004:0> t = Thread.new { raise ArgumentError, "test" } => # irb(main):005:0> t.join ArgumentError: test from (irb):4:in `block in irb_binding' irb(main):006:0> In other words: since the exception is not caught in the thread, thread exits but the exception survives. When you do the join, it will come to haunt you. This does make sense when you consider Thread.value: irb(main):006:0> t = Thread.new { "result" } => # irb(main):007:0> t.value => "result" irb(main):008:0> t = Thread.new { raise ArgumentError, "test" } => # irb(main):009:0> t.value ArgumentError: test from (irb):8:in `block in irb_binding' irb(main):010:0> Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/