I am asking for some aid in verifying the validity of this test and if someone could shed more light into the internals/what is actually happenning
I can confirm what you are seeing, and how you are interpreting it is correct.
When you start your worker thread, the perl variable $mw, which is closed over by the sub worker_thread() is cloned. But, as the tk internals are separate and unknown to Perl, it does not clone anything in tk space. Hence the two copies of $mw refer to the same tk state that hides behind it.
The problem is, that tk is not expecting to be called concurrently from multiple threads, so if you start making any kind of mutating use of those two copies, then tk's unprotected internal state will get corrupted and your program will crash.
If you were using strict & warnings you would see:
c:\test>junk.pl8 Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 6. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 7. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 10. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 11. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 15. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 15. Global symbol "$t" requires explicit package name at C:\test\junk.pl8 +line 18. Global symbol "$t" requires explicit package name at C:\test\junk.pl8 +line 19. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 23. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 24. Global symbol "$mw" requires explicit package name at C:\test\junk.pl8 + line 24. Execution of C:\test\junk.pl8 aborted due to compilation errors.
And if you cleaned those up you'd get:
c:\test>junk.pl8 from Main thread MainWindow=HASH(0x3a2e2c8):::0x00C90356 Attempt to free non-existent shared string '_TK_RESULT_', Perl interpr +eter: 0x3ac8314 at C:/perl32/lib/Tk/Submethods.pm line 37. from Worker thread MainWindow=HASH(0x3c926a4):::0x00C90356 Free to wrong pool 3ac5dc8 not 34ae9c8 at C:/perl32/lib/Tk/Widget.pm l +ine 98 during global destruction. Font {MS Sans Serif} 8 still in cache.
The "solution" is do not access tk from multiple threads; it will always crash. Usually sooner rather than later.
In reply to Re: Tk and thread local storage
by BrowserUk
in thread Tk and thread local storage
by nikosv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |