From: ara.t.howard@... Date: 2006-07-07T00:56:09+09:00 Subject: Re: [BUG] thread/sync.rb memory corruption On Thu, 6 Jul 2006, Robert Klemme wrote: > Yes, but they are still queued up against the mutex. I completely agree > with Tom's analysis. Having an Observer trigger the notification again is > definitively a bad idea - at least if events are not queued up. ah - but they are indeed queued - this is precisely what sync.rb is supposed to do. you can prove this for yourself by adding p 'Thread.list.size' => Thread.list.size in the notify method. if you do so you'll see something like on @ 1152201072.40667 {"Thread.list.size"=>1} off @ 1152201072.41042 {"Thread.list.size"=>2} on @ 1152201072.41508 {"Thread.list.size"=>3} off @ 1152201072.4219 {"Thread.list.size"=>3} on @ 1152201072.43386 {"Thread.list.size"=>2} off @ 1152201072.44186 {"Thread.list.size"=>3} on @ 1152201072.46079 {"Thread.list.size"=>2} the number of threads running will never exceed three. the bug does not seem to be directly caused by sync.rb in any case. here is a more minimal script which will produce the error: require 'sync' class A def initialize extend Sync_m @observers = [] end def meth synchronize(:EX){ @observers.each do |o| if ENV['CORRUPT'] o.notify nil else o.notify end end } end def add_observer o synchronize(:EX){ @observers << o } end end class B def initialize a @a = a @a.add_observer self end def notify *a Thread.new{ @a.meth } end end a = A.new b = B.new a a.meth STDIN.gets if you run it normally ruby a.rb it will run fine. if you run with CORRUPT=true ruby a.rb you will trash memory. if you have ef and do CORRUPT=true ef ruby a.rb electric fence will core dump almost immediately. note that the only difference between crashing and not is calling notify with and argument - when that occurs the number of threads will remain steady, but the GC will stop collecting finished threads even though no reference to them is held. regards. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama