Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > threads and io

Reply
Thread Tools

threads and io

 
 
gabriele renzi
Guest
Posts: n/a
 
      12-12-2003
il Fri, 12 Dec 2003 15:28:53 +0100, "JB" <> ha
scritto::

>I have soe problems whitn treads and I/O.
>
>My program starts severals threads that open tcp connections.
>The main thread waits the user to press Q to stop the program.
>
>It seems that the gets fonction blocks all my threads !!!
>How is it possible?
>What did I wrong?


if you're working on windows, that is a known issue I'm afraid
I remember this was related to windows select() maybe..
 
Reply With Quote
 
 
 
 
JB
Guest
Posts: n/a
 
      12-12-2003
I have soe problems whitn treads and I/O.

My program starts severals threads that open tcp connections.
The main thread waits the user to press Q to stop the program.

It seems that the gets fonction blocks all my threads !!!
How is it possible?
What did I wrong?

Thanks alot.

there is my programm

require 'socket'

#parametrers
$host = $*[0]
$port = $*[1]
$number = $*[2]
$number = 1 if ($number == nil)
$number = $number.to_i

#start threads
threads = []
for i in 1..($number)
threads << Thread.new(i) { |i|
sleep (rand(10))
while(1)
t = TCPSocket.new($host,$port)
sleep (rand(10))
t.close
sleep (rand(10))
end
}
end

print "Q to quit\n"
while(!($stdin.gets =~ /Q.*/))
end


 
Reply With Quote
 
 
 
 
Simon Strandgaard
Guest
Posts: n/a
 
      12-12-2003
On Fri, 12 Dec 2003 15:28:53 +0100, JB wrote:

> I have soe problems whitn treads and I/O.
>
> My program starts severals threads that open tcp connections.
> The main thread waits the user to press Q to stop the program.
>
> It seems that the gets fonction blocks all my threads !!!
> How is it possible?
> What did I wrong?


Tell us about what you are trying to accomplish?
make a server? or a client?


Its seems to me, that you are confusing server/client.
A: using TCPSocket, is a client thing.
B: multiple threads which operates on the same port (server).


Take a look at the TCPServer class, here:
http://www.rubycentral.com/book/lib_network.html

--
Simon Strandgaard
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Threads - Get running threads Pedro Pinto Java 2 04-08-2008 11:44 PM
[new to threads] threads with UI and loop Une bévue Ruby 0 06-14-2006 10:22 AM
TB View, Threads, Threads with unread The Invisible Man Firefox 1 03-20-2006 02:09 AM
Standard Threads vs Weightless Threads yoda Python 2 08-01-2005 09:12 PM
threads without threads sindica@gmail.com C Programming 4 08-27-2004 09:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57