From: "Lars M." Date: 2003-01-22T01:23:27+09:00 Subject: [Threads + Sockets] Strange behavior This is a multi-part message in MIME format. ------=_NextPart_000_0060_01C1A2A0.64930BB0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, I attached a really simple and short script. If you run it, it works as expected. If you comment the bottom and uncomment the part directly above, however, it does not work as expected anymore, it does not execute the block of code simultanously 10 times anymore - it waits until one socket is finished and then another thread continues execution. It seems the socket is not local to the block of code - that maybe why the other threads don't touch it until it is closed (when the block of code is finished) -> maybe they all share _one_ socket, but I do not think that is what is happening. So if the socket is not local to the block of code, how can I make it local? Thanks for any help in advance. Ciao, -Lars ------=_NextPart_000_0060_01C1A2A0.64930BB0 Content-Type: application/octet-stream; name="weird.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="weird.rb" require 'socket' class ThreadingGroup def initialize nThreads @threads = Array.new @nThreads = nThreads end def start code 1.upto @nThreads do @threads.push(Thread.start {code.call}) end done = false while not done done = true 0.upto @nThreads - 1 do |index| if @threads[index].alive? done = false break end end end end end #~ @group = ThreadingGroup.new 10 #~ @group.start proc{ #~ begin #~ puts 'start' #~ socket = TCPSocket.open('', 80) #~ socket.close #~ ensure #~ puts 'done' #~ end #~ } @group = ThreadingGroup.new 10 @group.start proc { puts 'start' sleep 5 } ------=_NextPart_000_0060_01C1A2A0.64930BB0--