thread problem.....

Discussion in 'Ruby' started by Pokkai Dokkai, Oct 9, 2007.

  1. i want to make a program code ,but it ll take long time to execute
    so i am spiliting my program into thread ....

    but the general concept about thread is ,it will reduce the execution
    time of our program under good condition (depending RAM size,Processor
    speed ,etc.....)

    But if the number of thread is more than that capacity of RAM ,Processor
    speed,and other resouces.....then the program will be very very slow

    so i want to check all the resource status(RAM ,processor,etc..) ,after
    creating everyone child thread from parent thread ...

    so how can i find the resource status(RAM ,processor,etc..) in the
    parent thread .
    so i can decide about to create next child thread.....

    any idea.....
    --
    Posted via http://www.ruby-forum.com/.
     
    Pokkai Dokkai, Oct 9, 2007
    #1
    1. Advertising

  2. Michael Bevilacqua-Linn wrote:
    > 2.) The current version of Ruby only supports green threads anyhow. So
    > even
    > if you did have multiple cores, you wouldn't get a speedup.
    >
    > MBL


    green thread means ?...
    --
    Posted via http://www.ruby-forum.com/.
     
    Pokkai Dokkai, Oct 9, 2007
    #2
    1. Advertising

  3. Pokkai Dokkai

    Greg Willits Guest

    Pokkai Dokkai wrote:
    > Michael Bevilacqua-Linn wrote:
    >> 2.) The current version of Ruby only supports green threads anyhow. So
    >> even
    >> if you did have multiple cores, you wouldn't get a speedup.
    >>
    >> MBL

    >
    > green thread means ?...


    threads managed by the language you're working in rather than by the
    operating system

    http://en.wikipedia.org/wiki/Green_threads

    --gw
    --
    Posted via http://www.ruby-forum.com/.
     
    Greg Willits, Oct 9, 2007
    #3
  4. Pokkai Dokkai

    7stud -- Guest

    Michael Bevilacqua-Linn wrote:
    > 1.) The only way threads get you a speedup is when you write your code
    > in
    > such a way that sections of it can be executed in parallel so you can
    > take
    > advantage of multiple cores (or processors).
    >
    > 2.) The current version of Ruby only supports green threads anyhow. So
    > even
    > if you did have multiple cores, you wouldn't get a speedup.
    >
    > MBL


    Then perhaps you could explain the output of this program:

    require 'rtiming' #a simple program that times methods

    def test1
    threads = []

    2.times do |i|
    threads = Thread.new do
    sleep(2)
    puts "task #{i+1} finished"
    end
    end

    threads.each do |t|
    t.join
    end
    end

    def test2
    sleep(2)
    puts "task 1 finished"

    sleep(2)
    puts "task 2 finished"
    end

    puts timer:)test1, 1)
    puts timer:)test2, 1)


    --output:---
    task 2 finished
    task 1 finished
    Method exec time(1 loops): 2.010791 total
    task 1 finished
    task 2 finished
    Method exec time(1 loops): 4.000226 total
    --
    Posted via http://www.ruby-forum.com/.
     
    7stud --, Oct 9, 2007
    #4
  5. Pokkai Dokkai

    Guest

    On Tue, 9 Oct 2007, Michael Bevilacqua-Linn wrote:

    > 1.) The only way threads get you a speedup is when you write your code in
    > such a way that sections of it can be executed in parallel so you can take
    > advantage of multiple cores (or processors).
    >
    > 2.) The current version of Ruby only supports green threads anyhow. So even
    > if you did have multiple cores, you wouldn't get a speedup.


    It's not that simple. With Ruby's green threads, it all depends on
    whether there's a latency somewhere, in one thread, that can allow another
    to make use of that time and get something done.

    You aren't going to find that latency in any CPU bound operation, and you
    aren't going to find that latency in any extension to Ruby that was not
    written to be Ruby aware.

    If your problem is IO bound, though, ruby can capture that time where one
    thread is waiting on IO to let another thtread do something. In those
    cases, you can get a speedup from Ruby's green threads.


    Kirk Haines
     
    , Oct 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. Charles A. Lackman

    Terminating a thread from the main thread

    Charles A. Lackman, Dec 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,584
    Herfried K. Wagner [MVP]
    Dec 9, 2004
  2. Manisha
    Replies:
    2
    Views:
    565
  3. NaeiKinDus
    Replies:
    1
    Views:
    603
    Jack Klein
    Apr 14, 2007
  4. NaeiKinDus
    Replies:
    3
    Views:
    637
    James Kanze
    Apr 15, 2007
  5. Replies:
    3
    Views:
    178
Loading...

Share This Page