use Module::Load::Conditional qw[can_load]; # Are we running threads? my $grThreaded = eval 'use threads; 1'; # If so, load thread modules my ($grThreadModules) = { 'threads::shared' => undef, 'Thread::Semaphore' => undef, }; if ( $grThreaded ) { unless ( can_load( modules => $grThreadModules ) ) { print "ERROR: Cannot load threaded modules in $0. Exiting."; exit(); } } use strict; my($gnWarning); if ( $grThreaded ) { # Does not work at all: Undefined subroutine &main::share # share($gnWarning); # This works in the debugger # However, if used in production: # Argument to share needs to be passed as ref # threads::shared::share($gnWarning); # This works at run time # However, if used under the debugger: # Type of arg 1 to threads::shared::share must be one of [$@%] # (not single ref constructor) threads::shared::share(\$gnWarning); }

In the code, I found that just trying to declare a variable as shared fails as being an undefined subroutine.

If I give the full variable module/name, it will work, but if I try to use the Perl debugger, I have to use a reference to the variable.

So I'm stumped as to the behavior. I'm running perl 5.20.1 under Linux.

Thanks, Bill


In reply to Problem conditionally making variables shared if using threads by billgdev

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.