perl 5.8.2/3 - thread started by a thread

From: pawo (pawo2000_at_wp.pl)
Date: 02/16/04


Date: Mon, 16 Feb 2004 14:18:24 +0100

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;
--------------------------------

Thank you in advance.

-- 
pawo
[spadam b za duzo gadam]


Relevant Pages

  • Re: how to start thread in thread
    ... I created a piece of code which starts a first thread. ... > in turn creates a second thread (It's only testing but I will need such ... > sub start { ... I suspect you have a synchronisation problem: ...
    (comp.lang.perl.misc)
  • how to start thread in thread
    ... I'm a perl beginner. ... I created a piece of code which starts a first thread. ... my $class = shift; ... sub start { ...
    (comp.lang.perl.misc)
  • how to start thread in thread
    ... I'm a perl beginner. ... I created a piece of code which starts a first thread. ... my $class = shift; ... sub start { ...
    (comp.lang.perl.misc)
  • sitemap generator for Perl
    ... I want to run the sitemap generator ... Returns the minimum number of links to traverse from the root URL of ... my $class = shift; ...
    (perl.beginners)
  • Re: How can I create instantiable objects (not classes)?
    ... a child object inherits not only its parent object's ... sub fee { ... my $class = shift; ... For example, an object of type Car might receive a message named "ticket," and since a car does not know what to do with a ticket, it would pass that message to an object of type Driver. ...
    (comp.lang.perl.misc)