--YZ5djTAD1cGYuMQK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Mar 01, 2006 at 11:04:31PM +0900, Mike wrote: > while (session erver.accept) > threads << Thread.new(session) do |ts| > ts.print "What's your name?\r\n" > puts "Request: #{s s.gets.chomp!}" > ts.print "\r\nHello #{s}, thanks for stopping by\r\n\r\n" > ts.close > end > break if s 'close' > end You have a race condition. "s 'close'" is getting evaluated before "s s.gets.chomp!". That's why the program doesn't exit until the next time through the loop. In this solution, the child thread causes the main thread to raise an exception, breaking out of the accept() call: require 'socket' p 333 server CPServer.new('0.0.0.0', p) loop do begin Thread.new(server.accept) do |ts| ts.print "What's your name?\r\n" puts "Request: #{s s.gets.chomp!}" if s 'close' Thread.main.raise "Closing" else ts.print "\r\nHello #{s}, thanks for stopping by\r\n\r\n" end ts.close end rescue puts "Exiting" break end end regards, Ed --YZ5djTAD1cGYuMQK Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFEBbpmnhUz11p9MSARAjZGAKCEQDpWdsdrScg9zuX4V2G43q8hYQCfXkqk pKpfsOlzLge6OtCyDWuHmYA`2e -----END PGP SIGNATURE----- --YZ5djTAD1cGYuMQK--