"stack level too deep"... because Threads keep their "starting" stack

Discussion in 'Ruby' started by Sam Roberts, Feb 11, 2005.

  1. Sam Roberts

    Sam Roberts Guest

    It appears threads keep their callers stack. Reasonable. But they do
    this when their caller was a thread, and it can lead to problems.

    Is there any way to strip your calling context, or does it break the
    language somehow? Is it needed for purposes other than debugging?

    Cheers,
    Sam


    $ ruby18 xthrd.rb
    ................................................................................................................................................................................................................................stack level too deep

    $ cat xthrd.rb

    $stdout.sync = true

    class Cache
    def resweep( period )
    Thread.new do
    begin
    #sleep( period )
    sweep_cache
    rescue
    puts $!
    # $!.backtrace.each { |s| puts s }
    exit 1
    end
    # then return, so we cease to exist, freeing our resources... right?
    end
    end

    def sweep_cache
    $stdout.write "."
    resweep(1)
    end

    end


    c = Cache.new

    c.resweep(1)

    loop do
    sleep 60
    end


    ^^^^^^^^^^^^


    What I was trying to do was when I saw something needed to be done to
    the cache in some amount of seconds, spin off a Thread that would sleep
    for those seconds, then do the work.

    However, the work might involve noticing new work to be done some time.
    So, spin off another thread to do the work, and finish your own work. No
    problem... ???

    I'm going to do this differently, but I thought it was interesting and
    unexpected.
    Sam Roberts, Feb 11, 2005
    #1
    1. Advertising

  2. Hi,

    In message "Re: "stack level too deep"... because Threads keep their "starting" stack"
    on Fri, 11 Feb 2005 13:19:53 +0900, Sam Roberts <> writes:

    |Is there any way to strip your calling context, or does it break the
    |language somehow? Is it needed for purposes other than debugging?

    No way to strip. It's a limitation of the current thread
    implementation.

    matz.
    Yukihiro Matsumoto, Feb 11, 2005
    #2
    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. Eric Schwartz

    stack level too deep on ia64

    Eric Schwartz, Nov 10, 2003, in forum: Ruby
    Replies:
    3
    Views:
    146
    Eric Schwartz
    Nov 11, 2003
  2. Jesper Olsen
    Replies:
    7
    Views:
    562
    Van Jacques
    Jan 16, 2004
  3. E.-R. Bruecklmeier

    [Q] YAML Error: stack level too deep

    E.-R. Bruecklmeier, Jul 6, 2004, in forum: Ruby
    Replies:
    4
    Views:
    196
    haldane
    Jul 6, 2004
  4. Ronny Voelker
    Replies:
    0
    Views:
    216
    Ronny Voelker
    Sep 24, 2004
  5. Replies:
    1
    Views:
    136
    Ruby.Dev
    Sep 26, 2005
Loading...

Share This Page