P
pawo
Hello everyone,
I'm a perl beginner. I created a piece of code starting a first thread which
in turn creates a second thread. Unfortunately the creation of the second
thread hangs the first one. Is there anybody who knows what's going on ?.
I decided to create fully OO software and I wouldn't like to go back into a
fork-based solution.
I also included my test application (I know there are no joins but it's only
for testing purposes)
--------------- test.pl -----------------------
#!/usr/bin/perl -w
use strict;
use Config;
$Config{useithreads} or die "recompile Perl with threads to run this
program.";
use ThrdTest;
#new object
my $object = ThrdTest->new;
#does sth
$object->start;
#wait for a carrige return
my $svalue = <>;
print "\nFINISHED\n";
------------ ThrdTest.pm ------------
package ThrdTest;
use strict;
use threads;
sub new {
my $class = shift;
my $self = {};
bless $self , $class;
return $self;
}
sub start {
my $self = shift;
threads->new(\&aaa, $self, "1");
threads->new(\&ddd, $self,"2");
}
sub aaa {
my $self = shift;
my $val = shift;
while(1) {
print $val;
}
}
sub ddd{
my $self = shift;
my $val = shift;
threads->new(\&aaa, $self, $val); # THE FIRST THREAD STALLS RIGHT HERE
}
return 1;
I'm a perl beginner. I created a piece of code starting a first thread which
in turn creates a second thread. Unfortunately the creation of the second
thread hangs the first one. Is there anybody who knows what's going on ?.
I decided to create fully OO software and I wouldn't like to go back into a
fork-based solution.
I also included my test application (I know there are no joins but it's only
for testing purposes)
--------------- test.pl -----------------------
#!/usr/bin/perl -w
use strict;
use Config;
$Config{useithreads} or die "recompile Perl with threads to run this
program.";
use ThrdTest;
#new object
my $object = ThrdTest->new;
#does sth
$object->start;
#wait for a carrige return
my $svalue = <>;
print "\nFINISHED\n";
------------ ThrdTest.pm ------------
package ThrdTest;
use strict;
use threads;
sub new {
my $class = shift;
my $self = {};
bless $self , $class;
return $self;
}
sub start {
my $self = shift;
threads->new(\&aaa, $self, "1");
threads->new(\&ddd, $self,"2");
}
sub aaa {
my $self = shift;
my $val = shift;
while(1) {
print $val;
}
}
sub ddd{
my $self = shift;
my $val = shift;
threads->new(\&aaa, $self, $val); # THE FIRST THREAD STALLS RIGHT HERE
}
return 1;