Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


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.

In reply to Re: Tk and thread local storage by BrowserUk
in thread Tk and thread local storage by nikosv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 16:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found