perl 5.8.2/3 - thread started by a thread

Discussion in 'Perl' started by pawo, Feb 16, 2004.

  1. pawo

    pawo Guest

    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]
     
    pawo, Feb 16, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rabbits77
    Replies:
    1
    Views:
    509
    John C. Bollinger
    Feb 25, 2004
  2. sarmin kho

    thread already started...

    sarmin kho, Feb 21, 2004, in forum: Python
    Replies:
    1
    Views:
    374
    Jarek Zgoda
    Feb 21, 2004
  3. Bernd Kaiser

    kill/cancel a started thread

    Bernd Kaiser, Aug 25, 2004, in forum: Python
    Replies:
    0
    Views:
    367
    Bernd Kaiser
    Aug 25, 2004
  4. Deepak Sarda

    checking a thread has started

    Deepak Sarda, Nov 6, 2004, in forum: Python
    Replies:
    13
    Views:
    539
    Deepak Sarda
    Nov 8, 2004
  5. Jake Barnes
    Replies:
    2
    Views:
    311
Loading...

Share This Page