[Israel.pm] Scalars leaked on threaded Perl
Shmuel Fomberg
semuelf at 012.net.il
Wed Dec 19 13:58:01 PST 2007
Hi All.
Well, I was improving my embedded module, and add an option to make threaded
plugins. (in a master-workers pattern)
Anyway, I got the following error:
Scalars leaked: 2
For every thread that opened. Tried a lot of things, but no avail.
Today I come across this perlmonks thread:
http://www.perlmonks.org/?node_id=280529
To save you the effort of reading it, the thing was that I had a function
that creates the thread:
sub AcceptRequest {
my ($self, $params) = @_;
....
my $thr = threads->create(\&Worker);
Doing the " my ($self, $params) = @_;" actually keeps these variable inside
the @_ array. Apparently, some bug in the thread creating and data
duplication handle @_ wrong. So what I had to do is to make this tiny
change:
sub AcceptRequest {
my $self = shift;
my $params = shift;
....
my $thr = threads->create(\&Worker);
And walla. Problem solved.
Happy Coding,
Shmuel.
More information about the Perl
mailing list