Skip Menu |

This queue is for tickets about the forks CPAN distribution.

Report information
The Basics
Id: 56139
Status: resolved
Priority: 0/
Queue: forks

People
Owner: Nobody in particular
Requestors: IKEGAMI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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.
I agree it is inconvenient to expect to load forks::shared at all times, "just in case". I'm willing to entertain auto-loading forks::shared (internally), but I'll need to review for any compatibility concerns it may cause with existing environments. (Perhaps adding a new hook to not auto-load forks::shared will solve this for the few outlier cases that may exist today.) Note: If you have an unthreaded Perl (e.g. useithreads=undef), forks Makefile.pl will prompt to optionally install it as a full namespace replacement for threads and threads::shared, which avoids this issue. On Tue Mar 30 22:28:27 2010, ikegami wrote: Show quoted text
> The following doesn't use anything from shared, so it shouldn't have to > load forks::shared explicitly. > > ---------- 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.
This has been addressed in the 0.34 release. Now, just do: perl -Mforks script.pl and use/require threads::shared will quietly load forks::shared, as desired.