<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -369,8 +369,16 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
       end
 
       @ran = true
+      $0 = &quot;merb: master&quot;
       
-      start_transaction
+      if Merb::Config[:fork_for_class_load]
+        start_transaction
+      else
+        trap('INT') do 
+          Merb.logger.warn! &quot;Killing children&quot;
+          kill_children
+        end
+      end
 
       # Load application file if it exists - for flat applications
       load_file Merb.dir_for(:application) if File.file?(Merb.dir_for(:application))
@@ -397,9 +405,7 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
       if GC.respond_to?(:copy_on_write_friendly=)
         GC.copy_on_write_friendly = true
       end      
-      
-      $0 = &quot;merb: master&quot;
-      
+            
       loop do
         reader, @writer = IO.pipe
         pid = Kernel.fork
@@ -463,7 +469,7 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
       Merb.exiting = true unless status == 128
       
       begin
-        @writer.puts(status.to_s)
+        @writer.puts(status.to_s) if @writer
       rescue SystemCallError
       end
       
@@ -512,7 +518,7 @@ class Merb::BootLoader::LoadClasses &lt; Merb::BootLoader
     # ==== Parameters
     # file&lt;String&gt;:: The file to reload.
     def reload(file)
-      if RUBY_PLATFORM == &quot;java&quot; || RUBY_PLATFORM == &quot;windows&quot;
+      if Merb::Config[:fork_for_class_load]
         remove_classes_in_file(file) { |f| load_file(f) }
       else
         kill_children(128)</diff>
      <filename>lib/merb-core/bootloader.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,7 @@ module Merb
           :port                   =&gt; &quot;4000&quot;,
           :adapter                =&gt; &quot;runner&quot;,
           :reload_classes         =&gt; true,
+          :fork_for_class_load    =&gt; !RUBY_PLATFORM.in?(&quot;windows&quot;, &quot;java&quot;),
           :environment            =&gt; &quot;development&quot;,
           :merb_root              =&gt; Dir.pwd,
           :use_mutex              =&gt; true,</diff>
      <filename>lib/merb-core/config.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,74 +2,88 @@ module Merb
   module Rack
     class AbstractAdapter
     
+      def self.spawn_worker(port)
+        pid = Kernel.fork
+        start_at_port(port, @opts) unless pid
+
+        # pid means we're in the parent, which means continue the loop
+        throw(:new_worker) unless pid
+        
+        @pids[port] = pid
+        $CHILDREN = @pids.values
+      end
+    
       def self.start(opts={})
         @opts = opts
         $CHILDREN ||= []
+        parent = nil
         
-        pids = {}
+        @pids = {}
         port = (opts[:socket] || opts[:port]).to_i
         max_port = Merb::Config[:cluster] ? Merb::Config[:cluster] - 1 : 0
-        pid = nil
         
         Merb.logger.warn! &quot;Cluster: #{max_port}&quot;
         
-        $0 = &quot;merb: spawner&quot;
+        if max_port == 0
+          start_at_port(port)
+          return
+        end
         
-        0.upto(max_port) do |i|          
-          pid = Kernel.fork
-          start_at_port(port + i, opts) unless pid
+        $0 = &quot;merb: spawner&quot;
 
-          # pid means we're in the parent, which means continue the loop
-          break unless pid
-          
-          $CHILDREN &lt;&lt; pid
-          pids[port + i] = pid
+        catch(:new_worker) do
+          0.upto(max_port) do |i|
+            parent = spawn_worker(port + i)
+          end
         end
 
         # pid means we're in the parent, so start watching the children
         # no pid means we're in a child, so just move on
-        return unless pid
+        return unless parent
 
         0.upto(max_port) do |i|
           Thread.new do
-            loop do
-              pid = pids[port + i]
-              begin
-                _, status = Process.wait2(pid)
-              rescue SystemCallError
-              ensure
-                Thread.exit if !status || status.exitstatus != 0 || Merb.exiting
-              end
+            catch(:new_worker) do
+              loop do
+                pid = @pids[port + i]
+                begin
+                  _, status = Process.wait2(pid)
+                rescue SystemCallError =&gt; e
+                ensure
+                  Thread.exit if !status || status.exitstatus != 0 || Merb.exiting
+                end
               
-              new_pid = Kernel.fork
-              start_at_port(port + i, opts) unless new_pid
-              break unless new_pid
-              pids[port + i] = new_pid
-              $CHILDREN = pids.values
+                spawn_worker(port + i)
+              end
             end
           end
         end
 
-        Process.waitall
+        sleep
         
       end
       
-      def self.start_at_port(port, opts)
+      def self.start_at_port(port, opts = @opts)
         at_exit do
           Merb::Server.remove_pid(port)
         end
         
         if Merb::Config[:daemonize]
           trap('INT') do
-            puts &quot;INT&quot;
             stop
             Merb.logger.warn! &quot;Exiting port #{port}\n&quot;
             exit_process
           end
-        else
+        elsif Merb::Config[:fork_for_class_load]
           trap('INT') { 1 }
         end
         
+        trap('HUP') do
+          stop
+          Merb.logger.warn! &quot;Exiting port #{port} on #{Process.pid}\n&quot;
+          exit_process
+        end
+        
         trap('ABRT') do
           stopped = stop(128)
           Merb.logger.warn! &quot;Exiting port #{port}\n&quot; if stopped</diff>
      <filename>lib/merb-core/rack/adapter/abstract.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ab4f142a2433452c940696d2f6bd9e23e375ea20</id>
    </parent>
  </parents>
  <author>
    <name>Yehuda Katz</name>
    <email>wycats@gmail.com</email>
  </author>
  <url>http://github.com/wycats/merb-core/commit/acb90a6e57e075717a235f5896df545937880416</url>
  <id>acb90a6e57e075717a235f5896df545937880416</id>
  <committed-date>2008-09-27T18:27:10-07:00</committed-date>
  <authored-date>2008-09-25T22:32:13-07:00</authored-date>
  <message>Forking setup works without any forking.</message>
  <tree>b915661f0e3532d1046a6ed030630b57c74970c6</tree>
  <committer>
    <name>Yehuda Katz</name>
    <email>wycats@gmail.com</email>
  </committer>
</commit>
