Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4296
| X-FeedAbuse | http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 |
|---|---|
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!talisker.lacave.net!lacave.net!not-for-mail |
| From | Joel VanderWerf <joelvanderwerf@gmail.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Re: Creating and Executing New Threads |
| Date | Wed, 11 May 2011 15:44:06 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 32 |
| Message-ID | <4DCAF500.8040505@gmail.com> (permalink) |
| References | <2fad4e571f05e17ee09ba2e4b856b9f4@ruby-forum.com> |
| NNTP-Posting-Host | bristol.highgroove.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | talisker.lacave.net 1305146722 48804 65.111.164.187 (11 May 2011 20:45:22 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Wed, 11 May 2011 20:45:22 +0000 (UTC) |
| In-Reply-To | <2fad4e571f05e17ee09ba2e4b856b9f4@ruby-forum.com> |
| 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 | 383008 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <4DCAF500.8040505@gmail.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:4296 |
Show key headers only | View raw
On 05/11/2011 01:32 PM, Dan King wrote:
> 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 }
>
All the threads are running in one process, hence there is only one pid.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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