Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4294

Creating and Executing New Threads

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!talisker.lacave.net!lacave.net!not-for-mail
From Dan King <dan.king106@yahoo.com>
Newsgroups comp.lang.ruby
Subject Creating and Executing New Threads
Date Wed, 11 May 2011 15:32:04 -0500
Organization Service de news de lacave.net
Lines 31
Message-ID <2fad4e571f05e17ee09ba2e4b856b9f4@ruby-forum.com> (permalink)
NNTP-Posting-Host bristol.highgroove.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-Trace talisker.lacave.net 1305146320 47146 65.111.164.187 (11 May 2011 20:38:40 GMT)
X-Complaints-To abuse@lacave.net
NNTP-Posting-Date Wed, 11 May 2011 20:38:40 +0000 (UTC)
X-Received-From This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway
X-Mail-Count 383006
X-Ml-Name ruby-talk
X-Rubymirror Yes
X-Ruby-Talk <2fad4e571f05e17ee09ba2e4b856b9f4@ruby-forum.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.ruby:4294

Show key headers only | View raw


I expected the script below to do the following:

(1) spawn a new thread
(2) connect to a server
(3) read the data transmitted by the server
(4) close the connection.
(5) repeat 1-4

While the script works, it does NOT spawn a new thread for each
connection. Does anyone why that is the case? Thanks.

require 'socket'

threads = []

500.times do
  threads << Thread.new do
    socket = TCPSocket.open('127.0.0.1', 23)
    pid = Process.pid
    while line = socket.gets
      print "Client thread (#{pid})\t" + line.chomp + "\n"
    end
    socket.close
  end
end

threads.each { |t| t.join }

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Creating and Executing New Threads Dan King <dan.king106@yahoo.com> - 2011-05-11 15:32 -0500
  Re: Creating and Executing New Threads Joel VanderWerf <joelvanderwerf@gmail.com> - 2011-05-11 15:44 -0500
  Re: Creating and Executing New Threads 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-11 17:52 -0500
    Re: Creating and Executing New Threads Christopher Dicely <cmdicely@gmail.com> - 2011-05-11 19:42 -0500
      Re: Creating and Executing New Threads 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-12 12:29 -0500

csiph-web