Requiring a module in one thread loads it for the entire process.

The script below traces out the content of %INC (as proof of what is loaded) three times.

  1. Once in main before a thread requires Tk.

    No Tk is visible to the main thread.

  2. Once in the thread after it has required Tk.

    The Tk modules are now visible. Within the thread.

  3. Once again in main after the thread has required Tk.

    The Tk modules remain invisible to the main thread.

Ergo. Anonymonk is right. You are wrong.

Live with it but don't talk about it cos no one is interested in how you are going to try to justify not just a wrong statement, but one where you tell someone who is so obviously correct, that they are wrong.

The oh so complicated test code:

#! perl -slw use strict; use threads; async{ sleep 4; require Tk; print for '2 ', keys %INC; }->detach; sleep 2; print for '1 ', keys %INC; sleep 6; print for '3 ', keys %INC;

And the proof:

C:\test>junk 1 XSLoader.pm warnings/register.pm strict.pm C:/Perl64/site/lib/sitecustomize.pl warnings.pm threads.pm overload.pm Config.pm 2 re.pm C:/Perl64/site/lib/sitecustomize.pl ActiveState/Path.pm Cwd.pm warnings.pm Tk/Wm.pm Symbol.pm C:/Perl64/site/lib/auto/Tk/getEncoding.al Exporter.pm Encode/Unicode.pm C:/Perl64/site/lib/auto/Tk/autosplit.ix Tk/Toplevel.pm File/Spec.pm File/Spec/Win32.pm Encode/Byte.pm warnings/register.pm XSLoader.pm Encode/Alias.pm Tk/Frame.pm Encode/Config.pm C:/Perl64/site/lib/auto/Tk/Toplevel/autosplit.ix Encode/Encoding.pm Tk/Pretty.pm Tk/Widget.pm Config_git.pl threads.pm base.pm Encode.pm C:/Perl64/site/lib/auto/Tk/Wm/autosplit.ix Tk/MainWindow.pm Tk/Submethods.pm Config.pm File/Basename.pm ActivePerl/Config.pm C:/Perl64/site/lib/auto/Tk/Widget/autosplit.ix Tk/Image.pm Carp.pm Tk/Event.pm bytes.pm File/Spec/Unix.pm Tk/Event/IO.pm vars.pm strict.pm Tk/Derived.pm constant.pm C:/Perl64/site/lib/auto/Tk/Frame/autosplit.ix Config_heavy.pl Tk/Configure.pm Tk/After.pm overload.pm AutoLoader.pm Tk/CmdLine.pm DynaLoader.pm Tk.pm 3 XSLoader.pm warnings/register.pm strict.pm C:/Perl64/site/lib/sitecustomize.pl warnings.pm threads.pm overload.pm Config.pm

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^5: Semaphores failing to prevent race condition (O loverly. A setup!) by BrowserUk
in thread Semaphores failing to prevent race condition by Llew_Llaw_Gyffes

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.