Scalars Leaked and Segmentation Fault

Discussion in 'Perl Misc' started by AMLiapunov, Feb 21, 2006.

  1. AMLiapunov

    AMLiapunov Guest

    Hi all,
    this is my first post on this group.
    I'm developing a distribuited application with perl 5.8.7 and ithreads.
    I'm experiencing scalars leaked problem and segmentation fault too.
    Each module of the code uses strict and warnings.
    As you can imagine it is very difficult to perform a debug of the code
    as i've no debug informations from the interpreter.

    Anyone could share opinions or comments.

    Thanks
     
    AMLiapunov, Feb 21, 2006
    #1
    1. Advertising

  2. AMLiapunov

    zentara Guest

    On Tue, 21 Feb 2006 12:53:19 GMT, AMLiapunov <> wrote:

    >Hi all,
    >this is my first post on this group.
    >I'm developing a distribuited application with perl 5.8.7 and ithreads.
    >I'm experiencing scalars leaked problem and segmentation fault too.
    >Each module of the code uses strict and warnings.
    >As you can imagine it is very difficult to perform a debug of the code
    >as i've no debug informations from the interpreter.
    >
    >Anyone could share opinions or comments.


    You should show a minimum example of code, but in general......

    You can get those scalars leaked error messages IIRC, if you
    do something like let a thread(s) die before joining. I guess it means
    that there are still refs to some variable used in the thread, but
    the thread no longer exists. Like I said IIRC....I remember seeing
    a few of those errors, last time I played with the newer threads in
    Gtk2, where you can launch threads after a gui was created.
    I have some code which will produce those errors, but really havn't
    found the cause.

    The only way I have found, to safely run threads, is to create all
    threads, before you create the main part of your script. That way,
    they don't share any code, (and possibly refs).
    Also I am guessing it is a harmless error, as long as your memory use
    is not rising, much like the common "a thread exited while others were
    running". The warnings may be annoying, but are harmless.

    The segfault is more serious, and most likely comes from shraing objects
    across threads, or creating a thread after the main thread already has
    an object ( which gets copied ) and raises havoc, ( google for objects
    and thread safety).

    In case you are running the threads from a GUI, the latest Gtk2 libs
    have some extra thread-safety included, where you start the script with
    ##############################################
    use Gtk2 qw/-init -threads-init/;

    #this line causes the warning, but dosn't die
    die "Glib::Object thread safetly failed"
    unless Glib::Object->set_threadsafe (TRUE);
    ##############################################

    Under carefully controlled conditions, this lets you launch threads
    after the GUI is created, and you control when you enter and leave a
    thread with
    Gtk2::Gdk::Threads->enter;
    Gtk2::Gdk::Threads->leave;


    But even with those features, you can still get scalars-leaked errors
    when you spawn-and-join threads in a running program, but they seem
    harmless and don't affect memory usage. In my tests, they seem to happen
    when I join a thread, which was created after the main script was up and
    running. Like I said, I'm guessing that the new thread got a useless
    copy of some variable from main, and the ref count went up, but when the
    thread was joined, it was cleaned up properly.





    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html
     
    zentara, Feb 23, 2006
    #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. Replies:
    1
    Views:
    462
    Bob Hairgrove
    Feb 19, 2004
  2. Jane Austine
    Replies:
    2
    Views:
    354
    Steven Taschuk
    Jul 2, 2003
  3. Jane Austine
    Replies:
    1
    Views:
    473
    Erik Max Francis
    Jul 2, 2003
  4. niry
    Replies:
    5
    Views:
    117
  5. Bernard Chan

    Scalars Leaked

    Bernard Chan, Jan 16, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    95
    Bernard Chan
    Jan 16, 2006
Loading...

Share This Page