Using fork method for spawn. I have a daemon which spawns jobs on request, but I wanted to limit concurrency, so created 3 worker threads to do the spawning within. I then ran into this race condition, and extracted the failure into the simplified code below. Any ideas? I was unable to figure out what is going wrong. Its probably something weird in my environment as I can't duplicate it in a fresh rails app
foo.rb:
class SpawnInit
include Spawn
def initialize
sid = spawn do
puts "Spawn initialized"
end
wait([sid])
end
end
threads = []
threads << Thread.new { SpawnInit.new }
threads << Thread.new { SpawnInit.new }
threads.each {|t| t.join}
within RAILS_ROOT
./script/runner foo.rb
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:285:in `stop': stopping only thread (ThreadError)
note: use sleep to stop forever
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:285:in `mon_acquire'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:214:in `mon_enter'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:240:in `synchronize'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/logger.rb:496:in `write'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/logger.rb:326:in `add'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/logger.rb:374:in `info'
from /Users/mconway/Documents/eclipse/workspace/sml/vendor/plugins/spawn/lib/spawn.rb:118:in `fork_it'
from /Users/mconway/Documents/eclipse/workspace/sml/vendor/plugins/spawn/lib/spawn.rb:90:in `fork'
... 9 levels...
from /Users/mconway/Documents/eclipse/workspace/sml/vendor/rails/railties/lib/commands/runner.rb:45
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from ./script/runner:3
Spawn initialized
Some more info, this does happen with a fresh rails app once you replace the logger in environment.rb: