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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |