Threading in ruby is retarded .....?~!

Discussion in 'Ruby' started by Sal Syed, Sep 1, 2007.

  1. Sal Syed

    Sal Syed Guest

    I'm running the latest version an Ruby and the way threads work makes
    absolutely no sense to me...

    I have the simplest use of threads:
    Code:
    Thread.new do
    while true
    puts "Enter command"
    if gets.chomp=='exit'
    break;
    
    end
    puts 'Ended service'
    end
    
    Thread.new do
    while service != nil
    server.start
    end end
    
    $user[:drbserver]=DistributedSearch.new($user,$database)
    service=DRb.start_service("druby://localhost:#{$config[:drbport]}",$user[:drbserver])
    DRb.thread.join
    
    When I run this DRb does NOT start until after I type in exit! Why does
    a new thread block the main thread wtf?????? I'm guessing this is not
    normal and has something to do with either DRb or Webrick. Isn't there a
    way that these two would just run their own threads...? It makes it
    useless to me if I can't run both in the same program
    --
    Posted via http://www.ruby-forum.com/.
    Sal Syed, Sep 1, 2007
    #1
    1. Advertising

  2. Sal Syed wrote:
    > I'm running the latest version an Ruby and the way threads work makes
    > absolutely no sense to me...
    >
    > I have the simplest use of threads:
    >
    Code:
    > Thread.new do
    > while true
    >   puts "Enter command"
    >         if gets.chomp=='exit'[/color]
    
    Are you using windows? This is a known problem:
    
    http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/ceec6a04e90ae4ba?tvc=2&q=gets+blocks+process+windows&hl=en
    
    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, Sep 1, 2007
    #2
    1. Advertising

  3. Sal Syed wrote:
    > I'm running the latest version an Ruby and the way threads work makes
    > absolutely no sense to me...

    ...
    > When I run this DRb does NOT start until after I type in exit! Why does
    > a new thread block the main thread wtf?????? I'm guessing this is not
    > normal and has something to do with either DRb or Webrick. Isn't there a
    > way that these two would just run their own threads...? It makes it
    > useless to me if I can't run both in the same program


    You could try it in JRuby, which uses normal operating system threads.
    No thread should be prevented from running unless you explicitly make it
    happen.

    - Charlie
    Charles Oliver Nutter, Sep 1, 2007
    #3
  4. Sal Syed

    Eric Hodel Guest

    On Sep 1, 2007, at 12:00, Sal Syed wrote:

    > I'm running the latest version an Ruby and the way threads work makes
    > absolutely no sense to me...
    >
    > I have the simplest use of threads:
    >
    Code:
    > Thread.new do
    > while true
    >   puts "Enter command"
    >         if gets.chomp=='exit'
    >         break;
    >
    > end
    > puts 'Ended service'
    > end
    >
    > Thread.new do
    >   while service != nil
    >   server.start
    > end end
    >
    > $user[:drbserver]=DistributedSearch.new($user,$database)
    > service=DRb.start_service("druby://localhost:#{$config[:drbport]}",
    > $user[:drbserver])
    > DRb.thread.join
    > 
    >
    > When I run this DRb does NOT start until after I type in exit! Why
    > does
    > a new thread block the main thread wtf?????? I'm guessing this is not
    > normal and has something to do with either DRb or Webrick. Isn't
    > there a
    > way that these two would just run their own threads...? It makes it
    > useless to me if I can't run both in the same program


    Are you using windows? It is broken, not ruby. Don't use gets in
    the main thread.

    --
    Poor workers blame their tools. Good workers build better tools. The
    best workers get their tools to do the work for them. -- Syndicate Wars
    Eric Hodel, Sep 9, 2007
    #4
  5. Sal Syed

    ara.t.howard Guest

    On Sep 1, 2007, at 1:00 PM, Sal Syed wrote:

    > I'm running the latest version an Ruby and the way threads work makes
    > absolutely no sense to me...
    >
    > I have the simplest use of threads:
    >
    Code:
    > Thread.new do
    > while true
    >   puts "Enter command"
    >         if gets.chomp=='exit'
    >         break;
    >
    > end
    > puts 'Ended service'
    > end
    >
    > Thread.new do
    >   while service != nil
    >   server.start
    > end end
    >
    > $user[:drbserver]=DistributedSearch.new($user,$database)
    > service=DRb.start_service("druby://localhost:#{$config[:drbport]}",
    > $user[:drbserver])
    > DRb.thread.join
    > 
    >



    this code won't run at all. post a complete, but minimal, example
    and someone might be inclined to fix it for you. as it stands i have
    no idea wtf????????? service or wft???????? server are.

    the code above has at least one race condition in it as it stands:
    you race here

    while service != nil

    and

    service = ...

    in some cases service will be nice the first time, in others not.
    perhaps this intended but, again, it's hard to see without a
    meaningful code posting.

    you'll have to help use help you if you want to get complete answer.

    regards.

    a @ http://drawohara.com/
    --
    we can deny everything, except that we have the possibility of being
    better. simply reflect on that.
    h.h. the 14th dalai lama
    ara.t.howard, Sep 9, 2007
    #5
    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. Wayne Mote
    Replies:
    1
    Views:
    573
    jan V
    Aug 10, 2005
  2. Oli Filth

    Retarded IE bug

    Oli Filth, Jan 14, 2005, in forum: HTML
    Replies:
    3
    Views:
    364
    SpaceGirl
    Jan 15, 2005
  3. Replies:
    9
    Views:
    1,016
    Mark Space
    Dec 29, 2007
  4. Steven Woody
    Replies:
    0
    Views:
    394
    Steven Woody
    Jan 9, 2009
  5. Daniel Waite

    Watir is acting retarded

    Daniel Waite, Feb 5, 2009, in forum: Ruby
    Replies:
    12
    Views:
    404
    Tom Cloyd
    Feb 6, 2009
Loading...

Share This Page