The following doesn't use anything from shared, so it shouldn't have to
load forks::shared explicitly.
Show quoted text
---------- BEGIN CODE ----------
#!/usr/bin/perl
use strict;
use warnings;
use forks qw( async );
BEGIN {
require forks::shared
if @ARGV && $ARGV[0] == 1;
}
use Thread::Queue qw( );
my $q = Thread::Queue->new(qw( a b c d e f ));
my @threads;
for (1..2) {
push @threads, async {
while (my $i = $q->dequeue_nb()) {
print($i);
}
};
}
$_->join() for @threads;
print("\n");
---------- END CODE ----------
Yet if it doesn't, trouble arises.
---------- BEGIN OUTPUT ----------
$ perl a.pl 0
Subroutine threads::shared::cond_wait redefined at
/usr/lib/perl/5.8/threads/shared.pm line 13.
Prototype mismatch: sub threads::shared::cond_wait (\[$@%];\[$@%]) vs
none at /usr/lib/perl/5.8/threads/shared.pm line 13.
Subroutine threads::shared::cond_timedwait redefined at
/usr/lib/perl/5.8/threads/shared.pm line 14.
Prototype mismatch: sub threads::shared::cond_timedwait (\[$@%]$;\[$@%])
vs none at /usr/lib/perl/5.8/threads/shared.pm line 14.
Subroutine threads::shared::cond_signal redefined at
/usr/lib/perl/5.8/threads/shared.pm line 15.
Prototype mismatch: sub threads::shared::cond_signal (\[$@%]) vs none at
/usr/lib/perl/5.8/threads/shared.pm line 15.
Subroutine threads::shared::cond_broadcast redefined at
/usr/lib/perl/5.8/threads/shared.pm line 16.
Prototype mismatch: sub threads::shared::cond_broadcast (\[$@%]) vs none
at /usr/lib/perl/5.8/threads/shared.pm line 16.
abcdefabcdef
$ perl a.pl 1
abcdef
---------- END OUTPUT ----------
Note not just the warnings but the incorrect output.
Because of this, one has to always load forks::shared when one uses
forks (in case some module uses thread::shared), and that's silly. forks
should load forks::shared.