threads and io

Discussion in 'Ruby' started by gabriele renzi, Dec 12, 2003.

  1. 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..
     
    gabriele renzi, Dec 12, 2003
    #1
    1. Advertising

  2. gabriele renzi

    JB Guest

    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
     
    JB, Dec 12, 2003
    #2
    1. Advertising

  3. 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
     
    Simon Strandgaard, Dec 12, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. puzzlecracker

    tutorial on generics and threads and io

    puzzlecracker, Jan 29, 2006, in forum: Java
    Replies:
    7
    Views:
    832
    Paulus de Boska
    Jan 31, 2006
  2. yoda
    Replies:
    2
    Views:
    464
    =?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=
    Aug 1, 2005
  3. threads without threads

    , Aug 27, 2004, in forum: C Programming
    Replies:
    4
    Views:
    433
    William Ahern
    Aug 27, 2004
  4. Pedro Pinto

    Java Threads - Get running threads

    Pedro Pinto, Apr 8, 2008, in forum: Java
    Replies:
    2
    Views:
    1,485
    Arne Vajhøj
    Apr 9, 2008
  5. Une bévue
    Replies:
    0
    Views:
    176
    Une bévue
    Jun 14, 2006
Loading...

Share This Page