http://www.perlmonks.org?node_id=1018654


in reply to WMI query with Threads

the script is crashing perl with the following messsage.

Hm. Mixing up the trace output from your program with the error message (and posting it without <code></code> blocks so all the newlines get eaten by the html) makes life difficult for those of whom you are asking for help.

The actual message you are receiving is just:

Free to wrong pool 49c7480 not 163ea8, <FILE> line 5 during global des +truction.

And the first thing to say about that is it isn't "a crash". This is an informational message issued only when the program has ended and Perl is freeing up the memory used by the program.

Essentially, the program is finished, done and dusted, -- whether it has worked or not is a different matter -- and Perl has detected an anomaly in its usage of memory whilst cleaning up. It is telling you that you may want to look more closely at it, but it isn't actually crashing; and the program may have completely correctly despite that anomaly.

What the message is telling you is that a piece of memory that was allocated by one thread; is being freed within the context of another thread. Whilst that can cause problems within your program; the fact that it is only being detected "during global destruction" often means that it didn't prevent the program from working or completing.

Now to the possible causes of that anomaly.

The usual cause of this cross-over of memory from one thread to another is accidental closure of a thread subroutine over a variable created (explicitly or implicitly) within the main thread code. And there are two main ways for that to happen.

  1. Non-shared, lexical (my) variables declared in your main thread, and re-used (without re-declaration) within thread subroutines.

    I do not see any of these in your code.

    This can often happen accidentally when thread subroutines are position at the end of the file. You use (and properly declare) a variable within your main program; and then re-use the name within the subroutine, but forget to declare it locally, and thus you get an accidental closure with no warnings.

    My tip for avoiding this is to put your subroutines -- especially those use as threads; but it works for all subroutines -- at the top of your program before your main line code.

    It flies in the face of certain conventions; but it is the conventions that are flawed here.

  2. The use of package-scoped, non-lexical variable -- ie. variables used but not declared with my -- within subroutines used as threads.

    Your thread procedure has two of these:

    Global symbol "$pingit" requires explicit package name at 1018589.pl l +ine 81. Global symbol "$colItems" requires explicit package name at 1018589.pl + line 91.

You also have several other variables that you haven't declared with my:

Global symbol "$linecount" requires explicit package name at 1018589.p +l line 21. Global symbol "$row" requires explicit package name at 1018589.pl line + 23. Global symbol "$line" requires explicit package name at 1018589.pl lin +e 24. Global symbol "$mainparam" requires explicit package name at 1018589.p +l line 28. Global symbol "$thr0" requires explicit package name at 1018589.pl lin +e 29. Global symbol "$thr1" requires explicit package name at 1018589.pl lin +e 33. Global symbol "$thread_count" requires explicit package name at 101858 +9.pl line 53. Global symbol "$pingit" requires explicit package name at 1018589.pl l +ine 67. Global symbol "$colItems" requires explicit package name at 1018589.pl + line 97. 1018589.pl had compilation errors.

These would all be caught for you by use strict;

So, my suggestions to you are:

  1. Add use strict; to the top of your program.

    And then eliminate all those errors by declaring all your variables with my.

  2. Move your GetTimeZone() subroutine to the top of your program.

    Just before print "Starting main program\n"; would be good.

Then try re-running your program. The chances are that those two simple changes will make the problem 'go away', but if they do not, come back and post your modified code and we can try to help you further.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.