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

Hey

I tend to use threads to make things smooth ;) In this particular case I use Tk, ImageQuick and Thread::Queue::Any; Now, runing the script I get this error:
Attempt to free non-existent shared string '_ErrorInfo_',Perl interpre +ter: 0x27491c at C:\Perl\site\lib/Tk.pm line 411. Free to wrong pool 272c80 not 5a07858 at C:\Perl\site\lib/Tk.pm line 4 +11. Free to wrong pool 5a07858 not 272c80 at C:\Perl\site\lib/Tk/Widget.pm + line 98 during global destruction.
Now, my question isnt whats wrong (its quite much code, although I could break it down), but is there some way to debug what is freed and such, so I know what object/scalar/variable that makes this happen? If I knew this, I could solve many problems, instead of solving one. Knowing the way to solve is better than to know how to solve one problem eh?
I know its something about leaving a sub or so, perl wants to free mem used, but something aint there... or something :)

Thanks,
Ace

Replies are listed 'Best First'.
Re: Debugging Threads
by zentara (Cardinal) on Dec 12, 2005 at 16:37 UTC
    Well you havn't shown any code, but the error sure looks like you are trying to access Tk widgets from threads. You cannot do that. Threads can be used with Tk, but Tk is "NOT THREAD-SAFE". You have to create all threads before you use any Tk statements, and use Tk only in a single thread(normally the main thread). So if you are trying to launch a thread, from a sub, after Tk is up-and-running, the thread will have Tk code in it, even if it's code block dosn't contain Tk code.....because of the way threads are created by copying the parent.

    For what it is worth, if you want to access widgets from threads, you will need to use Gtk2 or Wx(which is based on Gtk2), and use it's thread->enter and thread->leave methods. Gtk2 is working toward real thread safety, Tk is not.


    I'm not really a human, but I play one on earth. flash japh
      Aha... Is there a way to go step by step in the code somehow?
        That is something I would like to learn myself. :-) If you have perl and Tk compiled with debugging support, and you havn't stripped them, you can run start perl under gdb, then run the Tk program, and watch for what happens. I'm only rudimentarily familiar with doing it, so you might want to google for "gdb perl Tk" or "debugging perl tk", and see what you can come up with.

        Maybe you could run it under ptkdb, and see what happens when you step thru it, but with threads( and Tk not being thread-safe), the error will be "weird" and may not follow a repeatable pattern. It will just happen seemingly at random times.


        I'm not really a human, but I play one on earth. flash japh