scorpion7 has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone run into the following error (very early on) in the execution of a threaded script:

panic: del_backref, *svp=0 phase=DESTRUCT refcnt=3 during global destruction.


Periodically run into this - causes the script to die and have not been able to clearly determine what/why/how this is occurring. For example, can run the script (parsing data sets) repeatedly (exact same data/situation) and it seems to fail at least once out of 10-15 re-executions. Because its not a constant result, it has made it rather difficult to determine why its happening.

Hoping that someone might have already run into this previously and may be able to provide some pointers on where to start on trying to determine resolution.


Thanks!

Replies are listed 'Best First'.
Re: Perl and Threading
by choroba (Cardinal) on Nov 01, 2023 at 15:46 UTC
    Do you detach or join all the threads?

    Do you use threads::shared?

    Do you use bare threads, or a wrapper like Thread::Queue? I highly recommend using it.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Using Thread::Queue.
      
      Logic:
      - Collect list of things to process (into a Thread::Queue)
      - Execute threads using Thread::Queue for loop
      - Each thread has what it needs to process a Queue item
      
      Using this style structure:
      @threads=map {
        threads->create(sub {
        (all things required for each thread to process a Thread::Queue item via a while(defined()) { } structure)
        });
        } 1 .. <numthreads>;
      $_->join for @threads
      
      Not using the threads:shared.  (Looked at it a couple times, but not sure that I've encountered a use case for it -or- simply don't have sufficiently complex code to justify?)
      
      Thanks!
      
        Are you using any modules in your script? Note that many modules aren't thread safe or need special handling to stay like that.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Perl and Threading
by ikegami (Patriarch) on Nov 08, 2023 at 03:15 UTC

    No idea, but I'd look at the XS modules I'm using to see if they're thread-safe.