perl 5.8.2/3 - thread started by a thread

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,129
Messages
2,570,770
Members
47,329
Latest member
FidelRauch

Latest Threads

Top