creating thread in PERL

Discussion in 'Perl Misc' started by janicehwang1325@yahoo.com, Jun 5, 2006.

  1. Guest

    hi experts,

    my code is as simple as the follow.

    use Thread;
    $thr = new Thread \&sub1; # Spawn the thread

    $thr->detach; # Now we officially don't care any more

    sub sub1 {
    $a = 0;
    while (1) {
    $a++;
    print "\$a is $a\n";
    sleep 1;
    }
    }


    however, when i compile it. The error occur stating "Undefined
    subroutine &threads::new called at sample_thread.pl line 2.". What is
    the reason?
     
    , Jun 5, 2006
    #1
    1. Advertising

  2. Brian Wakem Guest

    wrote:

    > hi experts,
    >
    > my code is as simple as the follow.
    >
    > use Thread;
    > $thr = new Thread \&sub1; # Spawn the thread



    Try:

    $thr = Thread->new(\&sub1);


    > $thr->detach; # Now we officially don't care any more
    >
    > sub sub1 {
    > $a = 0;
    > while (1) {
    > $a++;
    > print "\$a is $a\n";
    > sleep 1;
    > }
    > }
    >
    >
    > however, when i compile it. The error occur stating "Undefined
    > subroutine &threads::new called at sample_thread.pl line 2.". What is
    > the reason?



    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Jun 5, 2006
    #2
    1. Advertising

  3. Guest

    erm.. i din really get your reply. However, i do solve the problem by
    just reinstall Perl on FreeBSD.

    Brian Wakem wrote:
    > wrote:
    >
    > > hi experts,
    > >
    > > my code is as simple as the follow.
    > >
    > > use Thread;
    > > $thr = new Thread \&sub1; # Spawn the thread

    >
    >
    > Try:
    >
    > $thr = Thread->new(\&sub1);
    >
    >
    > > $thr->detach; # Now we officially don't care any more
    > >
    > > sub sub1 {
    > > $a = 0;
    > > while (1) {
    > > $a++;
    > > print "\$a is $a\n";
    > > sleep 1;
    > > }
    > > }
    > >
    > >
    > > however, when i compile it. The error occur stating "Undefined
    > > subroutine &threads::new called at sample_thread.pl line 2.". What is
    > > the reason?

    >
    >
    > --
    > Brian Wakem
    > Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    , Jun 12, 2006
    #3
    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. dpackwood
    Replies:
    3
    Views:
    1,813
  2. pawo
    Replies:
    0
    Views:
    502
  3. Aditi
    Replies:
    2
    Views:
    1,447
    Aditi
    Jun 24, 2005
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    308
    PerlFAQ Server
    Jan 23, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    693
    PerlFAQ Server
    Feb 3, 2011
Loading...

Share This Page