in reply to Threads: How to fix "Scalars leaked" Issue?
To debug problems like this, eliminate what doesn't matter until you find what does matter. This is the code you should have posted:
use strict; use warnings; use threads; sub PINGIT { print "PINGIT\n"; return 0; } sub THPING { print "THPING\n"; my @th; for (1..5) { push @th, threads->create(\&PINGIT); } $_->join for @th; return 0; } { my %opts; my @th; for (1..2) { if ($ARGV[0]) { # Doesn't generate error message push @th, threads->create(\&THPING); } else { # Generate error message push @th, threads->create(\&THPING, \%opts); } } $_->join for @th; }
>perl 807726.pl 0 THPING THPING PINGIT PINGIT PINGIT PINGIT PINGIT Scalars leaked: 1 Scalars leaked: 1 Scalars leaked: 1 PINGIT PINGIT PINGIT Scalars leaked: 1 Scalars leaked: 1 Scalars leaked: 1 Scalars leaked: 1 PINGIT PINGIT Scalars leaked: 1 Scalars leaked: 1 Scalars leaked: 1 >perl 807726.pl 1 THPING THPING PINGIT PINGIT PINGIT PINGIT PINGIT PINGIT PINGIT PINGIT PINGIT PINGIT
I don't know why that gives an error. It could very well be a bug in Perl. (See perlbug if you wish to submit a bug report.)
The problem is not specific to a version of Perl (reproduced on 5.8.0, 5.8.8, 5.10.0, 5.10.1) or to an OS (reproduced on WinXP, Linux).
|
|---|