Hello,

I am fairly new to ruby and also at writing multi-threaded apps, and I was 
hoping someone with a better mastery of both might look at a problem I'm 
having. :)

I am using the ruby module for fastcgi (available via the cvs repository 
under lib/fcgi/) with threads and am having some strange results.  This may 
be because fcgi is not thread-safe (I notice that ENV and stdout are treated 
as globals which wouldn't work in a threaded cgi setup), but the problems 
appear to be unrelated to this.

Basically, the thread which services the browser connection sometimes stops 
in the middle of the block of code and closes the connection to the browser.  
The results are unpredictable: sometimes the thread finished successfully, 
sometimes it doesn't.

I've included a copy of the cgi, but I think it might take someone with a 
better understanding of threading issues to look at the fcgi module.

-----------

#!/usr/bin/env ruby

require "thread"
require "fcgi"

FCGI.each do |fcgi|

  Thread.new(fcgi) { |f|

      f.out.print "Content-type:  text/html\r\n\r\n"

      # print some arbitrary data so we can make sure the thread is finishing
      f.out.print f.out.type, "<br>\n"
      f.out.print f.out.id, "<br>\n"
      f.out.methods.sort.each { |method| f.out.print "#{method}<br>\n" }

   }
  
end

----------

To duplicate the problem, simply execute this through your browser and reload 
the pages several times.  The output should vary quite a bit from page to 
page if you do it quickly.

Any suggestions would be appreciated.

Thanks,
-Brad