Professional Web Applications Themes

threads in perl - PERL Beginners

Hi, I need help in simple threaded solution. How can I join the active thread? After I was started the thread I want him to join itself at the end and go back to the main Example: # main program $thr1=new threads \&sub_name; $thr2=new threads \&sub_name; $thr3=new threads \&sub_name; $thr4=new threads \&sub_name; # threaded subroutine sub sub_name{ print ("\nIn the thread!\n"); # here I need help to join this thread after the print } I need that every started thread will be killed after finished and thread->list to be updated Thank you all, Igor Please email me to [email]igor.ryaboystarcore-dsp.com[/email]...

  1. #1

    Default threads in perl

    Hi,
    I need help in simple threaded solution.
    How can I join the active thread?

    After I was started the thread I want him to join itself at the end and go back to the main
    Example:

    # main program
    $thr1=new threads \&sub_name;
    $thr2=new threads \&sub_name;
    $thr3=new threads \&sub_name;
    $thr4=new threads \&sub_name;

    # threaded subroutine
    sub sub_name{
    print ("\nIn the thread!\n");
    # here I need help to join this thread after the print

    }

    I need that every started thread will be killed after finished and thread->list to be updated


    Thank you all,
    Igor
    Please email me to [email]igor.ryaboystarcore-dsp.com[/email]
    Igor Ryaboy Guest

  2. #2

    Default RE: threads in perl

    Not Exactly,
    I'll be more specific:
    I need to open a lot of threads with same name when passing different parameters to each. When inside each thread there is a system call which can take a lot of time. I want that after the system call ends the thread will close itself and remove itself from threads->list. For example:


    while(...) #here will be some condition concerned with currently running threads i.e threads->list
    $thr=new threads \&create_thread, $param;
    $param=$param+1;

    sub create_thread {
    print("\nNew thread was started\n");
    my create_param = _;
    system("...");
    print ("\nOld thread was finished\n");
    }

    Unfortunately this construction didn't worked because the threads->list didn't decremented by itself after the system call was finished?
    What should I do? Maybe use of "join" in some way?

    THANKS A LOT
    Igor


    -----Original Message-----
    From: zentara [mailto:zentarahighstream.net]
    Sent: Friday, October 10, 2003 7:44 PM
    To: [email]beginnersperl.org[/email]
    Subject: Re: threads in perl


    On Wed, 8 Oct 2003 13:13:13 +0200, [email]igor.ryaboystarcore-dsp.com[/email] (Igor
    Ryaboy) wrote:
    >Hi,
    >I need help in simple threaded solution.
    >How can I join the active thread?
    >
    >After I was started the thread I want him to join itself at the end and go back to the main
    >Example:
    >
    ># main program
    >$thr1=new threads \&sub_name;
    >$thr2=new threads \&sub_name;
    >$thr3=new threads \&sub_name;
    >$thr4=new threads \&sub_name;
    >
    ># threaded subroutine
    >sub sub_name{
    > print ("\nIn the thread!\n");
    > # here I need help to join this thread after the print
    >
    >}
    >
    >I need that every started thread will be killed after finished and thread->list to be updated
    Is this what you are thinking?

    #!/usr/bin/perl
    use threads;
    # join() does three things: it waits for a thread to exit,
    # cleans up after it, and returns any data the thread may
    # have produced.

    $thr1 = threads->new(\&sub1);
    $ReturnData1 = $thr1->join;
    print "Thread1 returned $ReturnData1\n";

    $thr2 = threads->new(\&sub2);
    $ReturnData2 = $thr2->join;
    print "Thread2 returned $ReturnData2\n";

    $thr3 = threads->new(\&sub3);
    $ReturnData3 = $thr3->join;
    print "Thread3 returned $ReturnData3\n";

    sub sub1 {
    values = ('1a','1b', '1c');
    return \values;
    }

    sub sub2 {
    values = ('2a','2b', '2c');
    return \values;
    }

    sub sub3 {
    values = ('3a','3b', '3c');
    return \values;
    }
    __END__


    Our body's 20 milligrams of beta radioactive Potassium 40
    emit about 340 million neutrinos per day, which go at
    lightspeed to the ends of the universe!..even thru the earth.

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]

    Igor Ryaboy Guest

  3. #3

    Default FW: threads in perl

    This is useful, thanks, but:
    I need in general to maintain a constant/fixed number of threads running i.e. when one is finished other will be started but I am not allowed to start more than x threads.
    How can I do it?
    I've tried to do it based on threads->list but the problem that I don't know which thread should I join.
    Thanks
    Igor

    -----Original Message-----
    From: zentara [mailto:zentarahighstream.net]
    Sent: Sunday, October 12, 2003 2:47 PM
    To: [email]beginnersperl.org[/email]
    Subject: Re: threads in perl


    On Sun, 12 Oct 2003 08:24:52 +0200, [email]igor.ryaboystarcore-dsp.com[/email] (Igor
    Ryaboy) wrote:
    >I'll be more specific:
    >I need to open a lot of threads with same name when passing different parameters to each.
    >When inside each thread there is a system call which can take a lot of time. I want that after
    >the system call ends the thread will close itself and remove itself from threads->list.
    >For example:
    >while(...) #here will be some condition concerned with currently running threads i.e threads->list
    > $thr=new threads \&create_thread, $param;
    > $param=$param+1;
    >
    >sub create_thread {
    > print("\nNew thread was started\n");
    > my create_param = _;
    > system("...");
    > print ("\nOld thread was finished\n");
    >}
    >
    >Unfortunately this construction didn't worked because the threads->list didn't
    >decremented by itself after the system call was finished?
    >What should I do? Maybe use of "join" in some way?
    Bear in mind I'm not a "threading expert", just a hacker with ideas. :-)
    Here is a snippet to try. I used a global for $param instead of passing
    it, but you may be able to pass the $param. Also maybe you should check
    out the module Thread::Pool, which manages threads and tasks.

    #!/usr/bin/perl
    use threads;
    my kiddies;
    my $param =10;

    while ($param > 0){
    print "$$ starting loop $_";
    push kiddies, threads->new(\&sub1);
    print "$$ exiting loop $_\n";
    $param--;
    }

    sub sub1{
    print "\tchild ", threads->tid(), " created ok using param $param\n";
    sleep(int(rand(10)));
    print "\tchild", threads->tid() , " done, outta here\n";
    }

    foreach (kiddies){ $_->join(); }
    __END__




    Our body's 20 milligrams of beta radioactive Potassium 40
    emit about 340 million neutrinos per day, which go at
    lightspeed to the ends of the universe!..even thru the earth.

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]

    Igor Ryaboy Guest

  4. #4

    Default Re: threads in perl

    On Sun, Oct 12, 2003 at 05:35:21PM +0200, Kevin Pfeiffer wrote:
    > In article <4piiovsfb0484amf1rfgbm8f8ot0ik8u7h4ax.com>, Zentara wrote:
    > > [email]igor.ryaboystarcore-dsp.com[/email] (Igor Ryaboy) wrote:
    > >
    > > foreach (kiddies){ $_->join(); }
    >
    > Printing these out (i.e.):
    > foreach (kiddies){
    > $_->join();
    > print "$_ joined.\n";
    > }
    >
    > gives me:
    > threads=SCALAR(0x81de948) joined.
    > threads=SCALAR(0x81e180c) joined.
    > etc.
    >
    > But what does that mean in slightly plainer English?
    That "package=TYPE(0xaddress)" is how perl stringifies an object
    reference. The objects in kiddies are SCALAR references blessed
    into package "threads".

    Plain scalar reference:

    % perl -le 'print \2'
    SCALAR(0x81aa374)

    Blessed scalar reference (object):

    % perl -le 'print bless \($x = 2), "threads"'
    threads=SCALAR(0x81aa3bc)

    --
    Steve
    Steve Grazzini Guest

  5. #5

    Default Re: threads in perl

    In article <4piiovsfb0484amf1rfgbm8f8ot0ik8u7h4ax.com>, Zentara wrote:
    > On Sun, 12 Oct 2003 08:24:52 +0200, [email]igor.ryaboystarcore-dsp.com[/email] (Igor
    > Ryaboy) wrote:
    [...]
    > Bear in mind I'm not a "threading expert", just a hacker with ideas. :-)
    > Here is a snippet to try. I used a global for $param instead of passing
    > it, but you may be able to pass the $param. Also maybe you should check
    > out the module Thread::Pool, which manages threads and tasks.
    >
    > #!/usr/bin/perl
    > use threads;
    > my kiddies;
    > my $param =10;
    >
    > while ($param > 0){
    > print "$$ starting loop $_";
    > push kiddies, threads->new(\&sub1);
    > print "$$ exiting loop $_\n";
    > $param--;
    > }
    >
    > sub sub1{
    > print "\tchild ", threads->tid(), " created ok using param $param\n";
    > sleep(int(rand(10)));
    > print "\tchild", threads->tid() , " done, outta here\n";
    > }
    >
    > foreach (kiddies){ $_->join(); }
    > __END__
    What does the last line do. I looked at man threads:
    $thread->join
    This will wait for the corresponding thread to join. When the
    thread finishes, join() will return the return values of
    the entry point function."

    Printing these out (i.e.):
    foreach (kiddies){
    $_->join();
    print "$_ joined.\n";
    }

    gives me:
    threads=SCALAR(0x81de948) joined.
    threads=SCALAR(0x81e180c) joined.
    etc.

    But what does that mean in slightly plainer English?

    -K

    --
    Kevin Pfeiffer
    International University Bremen


    Kevin Pfeiffer Guest

  6. #6

    Default Re: threads in perl

    In article <2393874.PabSaFVFErsputnik.tiros.net>, Kevin Pfeiffer wrote:
    [...]
    > What does the last line do. I looked at man threads:
    > $thread->join
    > This will wait for the corresponding thread to join. When the
    > thread finishes, join() will return the return values of
    > the entry point function."
    >
    > Printing these out (i.e.):
    > foreach (kiddies){
    > $_->join();
    > print "$_ joined.\n";
    > }
    >
    > gives me:
    > threads=SCALAR(0x81de948) joined.
    > threads=SCALAR(0x81e180c) joined.
    > etc.
    >
    > But what does that mean in slightly plainer English?
    Looking further I also tried threads->list() (as Igor mentions). Perldocs
    say:

    threads->list();
    This will return a list of all non joined, non detached threads.

    Shouldn't this give you an idea how many threads are still running?

    I tried this (also "print scalar threads->list()" trying to get a count),
    but the list remained unchanged the entire time...

    while(1) {
    sleep 3;
    print threads->list();
    print "\n";
    }




    --
    Kevin Pfeiffer
    International University Bremen
    A: Because it messes up the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    Kevin Pfeiffer Guest

  7. #7

    Default RE: FW: threads in perl

    Very Nice ,
    There is only one unsolved issue here: Your program may exit with other threads are still running , beside this I liked it very much. The actual solution you supplied is the use of threads->self function.
    Thanks you very much!!!
    Igor
    BTW where can I get some doentation about threads::Pool?


    -----Original Message-----
    From: zentara [mailto:zentarahighstream.net]
    Sent: Monday, October 13, 2003 1:16 AM
    To: [email]beginnersperl.org[/email]
    Subject: Re: FW: threads in perl


    On Sun, 12 Oct 2003 15:21:54 +0200, [email]igor.ryaboystarcore-dsp.com[/email] (Igor
    Ryaboy) wrote:
    >This is useful, thanks, but:
    >I need in general to maintain a constant/fixed number of threads running i.e. when one is finished other will be started but I am not allowed to start more than x threads.
    >How can I do it?
    >I've tried to do it based on threads->list but the problem that I don't know which thread should I join.
    >Thanks
    Just in case it may help you out, here is the snippet I came
    up with which seems to work with threads. I tested it in as much
    as I ran top and watched that only maxnum threads run at a time.


    #!/usr/bin/perl
    use warnings;
    use threads;
    #seems to work

    my data = qw(a b c d e f g h i j k l m n o p);
    my $workernum = 4;
    my $finished = 'false';
    my running_threads = ();

    while ($finished eq "false") {
    running_threads = threads->list;
    if (scalar(running_threads) < $workernum) {

    $somedata = shift data || undef;
    if (defined $somedata) {
    threads->new(\&worker, $somedata);
    } else {
    $finished = "true";
    }
    }
    }

    #cleanup leftover running threads
    print "data exhausted, waiting for threads to finish\n";
    threads->list()->join;


    #And this is the code for the worker:

    sub worker {
    # do whatever
    my $paramin = shift;
    print "\tchild ", threads->tid(), " created ok using param
    $paramin\n";
    sleep(int(rand(30)));
    print "\tchild", threads->tid() , " done, outta here\n";
    threads->self->join;
    }
    __END__



    Our body's 20 milligrams of beta radioactive Potassium 40
    emit about 340 million neutrinos per day, which go at
    lightspeed to the ends of the universe!..even thru the earth.

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]

    Igor Ryaboy Guest

  8. #8

    Default RE: threads in perl

    Hi,
    The program is still exits sometimes without waiting for the threads to finish . I can't understand it. It seem like the "join" just doesn't waits to the process to finish , it just cleans after the thread and decrements the threads->list.
    Igor

    -----Original Message-----
    From: zentara [mailto:zentarahighstream.net]
    Sent: Monday, October 13, 2003 8:19 PM
    To: [email]beginnersperl.org[/email]
    Subject: Re: FW: threads in perl


    On Mon, 13 Oct 2003 18:29:09 +0200, [email]igor.ryaboystarcore-dsp.com[/email] (Igor
    Ryaboy) wrote:
    >Very Nice ,
    >There is only one unsolved issue here: Your program may exit with other threads are
    >still running , beside this I liked it very much. The actual solution you supplied is the
    > use of threads->self function.
    ############################################
    Yeah I fixed this.
    >#cleanup leftover running threads
    >print "data exhausted, waiting for threads to finish\n";
    >threads->list()->join;
    Replace the above with:

    #cleanup leftover running threads
    print "data exhausted, waiting for threads to finish\n";
    while (1){
    running_threads = threads->list;
    if (scalar(running_threads) < 1){print "\nFinished\n";exit}else{next}
    }

    #################################################

    >Thanks you very much!!!
    Your welcome, it was a learning experience for me too. :-)
    >Igor
    >BTW where can I get some doentation about threads::Pool?
    Download the module from cpan. But I just checked out the latest
    version of Threads::Pool and it only works with perl5.8.0-RC3 or
    later. I installed 5.81 to test it, but 5.81 broke some other modules
    I'm playing with. So.....it's up to you.



    Our body's 20 milligrams of beta radioactive Potassium 40
    emit about 340 million neutrinos per day, which go at
    lightspeed to the ends of the universe!..even thru the earth.

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]

    Igor Ryaboy Guest

  9. #9

    Default threads in perl

    Hi All!

    I am running a multithread program and threads may stuck. I need to be able to terminate those threads after some defined period of time. I can't use a detach because I don't want to leave this thread run forever and I can't use join because the thread never ends. Any ideas? Please help :)

    Igor

    -----Original Message-----
    From: zentara [mailto:zentarahighstream.net]
    Sent: Monday, October 13, 2003 8:19 PM
    To: [email]beginnersperl.org[/email]
    Subject: Re: FW: threads in perl


    On Mon, 13 Oct 2003 18:29:09 +0200, [email]igor.ryaboystarcore-dsp.com[/email] (Igor
    Ryaboy) wrote:
    >Very Nice ,
    >There is only one unsolved issue here: Your program may exit with other threads are
    >still running , beside this I liked it very much. The actual solution you supplied is the
    > use of threads->self function.
    ############################################
    Yeah I fixed this.
    >#cleanup leftover running threads
    >print "data exhausted, waiting for threads to finish\n";
    >threads->list()->join;
    Replace the above with:

    #cleanup leftover running threads
    print "data exhausted, waiting for threads to finish\n";
    while (1){
    running_threads = threads->list;
    if (scalar(running_threads) < 1){print "\nFinished\n";exit}else{next}
    }

    #################################################

    >Thanks you very much!!!
    Your welcome, it was a learning experience for me too. :-)
    >Igor
    >BTW where can I get some doentation about threads::Pool?
    Download the module from cpan. But I just checked out the latest
    version of Threads::Pool and it only works with perl5.8.0-RC3 or
    later. I installed 5.81 to test it, but 5.81 broke some other modules
    I'm playing with. So.....it's up to you.



    Our body's 20 milligrams of beta radioactive Potassium 40
    emit about 340 million neutrinos per day, which go at
    lightspeed to the ends of the universe!..even thru the earth.

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]

    Igor Ryaboy Guest

  10. #10

    Default threads in perl

    Hi All!

    I am running a multithread program and threads may stuck. I need to be able to terminate those threads after some defined period of time. I can't use a detach because I don't want to leave this thread run forever and I can't use join because the thread never ends. Any ideas? Please help :)

    Igor
    Igor Ryaboy Guest

  11. #11

    Default RE: threads in perl

    Hi,
    (Please ignore the previous mail.)
    In this example this fellow detaches all useless threads. In my case this is not an option , because a detached thread never ends. For correct thread managing it is enough to remove the detached thread from the list but the process will still run. I need to kill the process! (Verilog simulation in my case)
    Thanks,
    Igor

    -----Original Message-----
    From: [email]Linuxonion.perl.org[/email] [mailto:Linuxonion.perl.org]On Behalf Of zentara
    Sent: Wednesday, January 14, 2004 5:28 PM
    To: [email]beginnersperl.org[/email]
    Subject: Re: threads in perl


    On Tue, 13 Jan 2004 17:17:20 +0200, [email]igor.ryaboystarcore-dsp.com[/email] (Igor
    Ryaboy) wrote:
    >Hi All!
    >
    >I am running a multithread program and threads may stuck. I need to be able to terminate those threads after some defined period of time. I can't use a detach because I don't want to leave this thread run forever and I can't use join because the thread never ends. Any ideas? Please help :)
    >
    >Igor
    Yeah, a fellow posting on perlmonks.org just did a nice job of this
    using threads::shared and sending some kill signals thru shared
    variables. It is a multi-threaded chat server, and he had a similar
    problem, killing off detached threads.
    It is quite long, but it works. Here is the url. I hope it may give you
    some ideas.

    [url]http://perlmonks.org/index.pl?replies=1&node_id=319769&displaytype=prin t[/url]



    --
    When life conspires against you, and no longer floats your boat,
    Don't waste your time with crying, just get on your back and float.

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Igor Ryaboy Guest

  12. #12

    Default RE: threads in perl

    Igor Ryaboy wrote:
    > Hi,
    > (Please ignore the previous mail.)
    > In this example this fellow detaches all useless threads. In my case this
    > is not an option , because a detached thread never ends.
    this is plain wrong.
    > For correct thread managing it is enough to remove the detached thread
    > from the list but the process will still run. I need to kill the process!
    > (Verilog simulation in my case) Thanks, Igor
    i don't know what you are asking for. do you want to kill the process and
    have all the threads gone? or do you want to kill the threads but still
    have the process running?

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)
    David Guest

  13. #13

    Default RE: threads in perl

    Hi
    I want to kill a specific thread and thread->list to be updated (Like thread->join but without waiting).
    Igor

    -----Original Message-----
    From: david [mailto:dzhuolooksmart.net]
    Sent: Wednesday, January 14, 2004 9:15 PM
    To: [email]beginnersperl.org[/email]
    Subject: RE: threads in perl


    Igor Ryaboy wrote:
    > Hi,
    > (Please ignore the previous mail.)
    > In this example this fellow detaches all useless threads. In my case this
    > is not an option , because a detached thread never ends.
    this is plain wrong.
    > For correct thread managing it is enough to remove the detached thread
    > from the list but the process will still run. I need to kill the process!
    > (Verilog simulation in my case) Thanks, Igor
    i don't know what you are asking for. do you want to kill the process and
    have all the threads gone? or do you want to kill the threads but still
    have the process running?

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Igor Ryaboy Guest

  14. #14

    Default RE: threads in perl

    Igor Ryaboy wrote:
    > Hi
    > I want to kill a specific thread and thread->list to be updated (Like
    > thread->join but without waiting). Igor
    >
    instead of killing a thread, why not just let the thread die when you need
    to kill it? take a look at Thread::Exit and Thread::Suspend, they let you
    kill / suspend / resume threads

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)
    David Guest

  15. #15

    Default RE: threads in perl

    Hi,
    Thanks for your tips,
    Where can I get those modules?
    Igor

    -----Original Message-----
    From: david [mailto:dzhuolooksmart.net]
    Sent: Monday, January 19, 2004 9:15 PM
    To: [email]beginnersperl.org[/email]
    Subject: RE: threads in perl


    Igor Ryaboy wrote:
    > Hi
    > I want to kill a specific thread and thread->list to be updated (Like
    > thread->join but without waiting). Igor
    >
    instead of killing a thread, why not just let the thread die when you need
    to kill it? take a look at Thread::Exit and Thread::Suspend, they let you
    kill / suspend / resume threads

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Igor Ryaboy Guest

  16. #16

    Default Re: threads in perl

    CPAN

    [url]http://search.cpan.org[/url]

    El Tue January 20 2004 03:44 Igor Ryaboy dijo :
    > Hi,
    > Thanks for your tips,
    > Where can I get those modules?
    > Igor
    >
    > -----Original Message-----
    > From: david [mailto:dzhuolooksmart.net]
    > Sent: Monday, January 19, 2004 9:15 PM
    > To: [email]beginnersperl.org[/email]
    > Subject: RE: threads in perl
    >
    > Igor Ryaboy wrote:
    > > Hi
    > > I want to kill a specific thread and thread->list to be updated (Like
    > > thread->join but without waiting). Igor
    >
    > instead of killing a thread, why not just let the thread die when you need
    > to kill it? take a look at Thread::Exit and Thread::Suspend, they let you
    > kill / suspend / resume threads
    >
    > david
    > --
    > sub'_{print"_ ";* \ = * __ ,\ & \}
    > sub'__{print"_ ";* \ = * ___ ,\ & \}
    > sub'___{print"_ ";* \ = * ____ ,\ & \}
    > sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    > For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    > <http://learn.perl.org/> <http://learn.perl.org/first-response>
    --
    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.1
    GM/B/CS d- s+:+ a-- C+ UL+++ P++++$ L++ E--- W N-- !o K? w !O !M V-- PS++
    PE++ Y PGP+++ t--- 5 X R- tv- b+++ DI- D+ G e h! r+++ y?
    ------END GEEK CODE BLOCK------
    Roberto Álamos moreno Guest

  17. #17

    Default RE: threads in perl

    Hi,
    I have a thread that invokes system("command") that may stuck. I can't let this thread die because it may take a lot of time. Example:

    threads->new(\&srun);
    ...
    ...
    sub srun {
    system("....");
    threads->self->join;
    }
    I need to kill the system command if it takes more than define timeout.

    Thanks,
    Igor

    -----Original Message-----
    From: david [mailto:dzhuolooksmart.net]
    Sent: Monday, January 19, 2004 9:15 PM
    To: [email]beginnersperl.org[/email]
    Subject: RE: threads in perl


    Igor Ryaboy wrote:
    > Hi
    > I want to kill a specific thread and thread->list to be updated (Like
    > thread->join but without waiting). Igor
    >
    instead of killing a thread, why not just let the thread die when you need
    to kill it? take a look at Thread::Exit and Thread::Suspend, they let you
    kill / suspend / resume threads

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Igor Ryaboy Guest

  18. #18

    Default RE: threads in perl

    Igor Ryaboy wrote:
    > Hi,
    > I have a thread that invokes system("command") that may stuck. I can't let
    > this thread die because it may take a lot of time. Example:
    >
    > threads->new(\&srun);
    > ..
    > ..
    > sub srun {
    > system("....");
    > threads->self->join;
    > }
    > I need to kill the system command if it takes more than define timeout.
    >
    this's a faq: perldoc -q timeout

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)
    David Guest

  19. #19

    Default RE: threads in perl

    I have no problem to alarm when timeout occurs in specific thread, I have a difficulty to abort a "system" command in that thread.

    -----Original Message-----
    From: david [mailto:dzhuolooksmart.net]
    Sent: Tuesday, January 20, 2004 9:14 PM
    To: [email]beginnersperl.org[/email]
    Subject: RE: threads in perl


    Igor Ryaboy wrote:
    > Hi,
    > I have a thread that invokes system("command") that may stuck. I can't let
    > this thread die because it may take a lot of time. Example:
    >
    > threads->new(\&srun);
    > ..
    > ..
    > sub srun {
    > system("....");
    > threads->self->join;
    > }
    > I need to kill the system command if it takes more than define timeout.
    >
    this's a faq: perldoc -q timeout

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)

    --
    To unsubscribe, e-mail: [email]beginners-unsubscribeperl.org[/email]
    For additional commands, e-mail: [email]beginners-helpperl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Igor Ryaboy Guest

  20. #20

    Default RE: threads in perl

    Igor Ryaboy wrote:
    > I have no problem to alarm when timeout occurs in specific thread, I have
    > a difficulty to abort a "system" command in that thread.
    in that case, fork a different process in your thread, replace system with
    exec and use the pid of the newly created process to abort itself when you
    need to. because exec replaces the running image, whatever you exec becomes
    the running process and because you have the pid to it, you can easily
    abort it without affecting the thread or your main process.

    david
    --
    sub'_{print"_ ";* \ = * __ ,\ & \}
    sub'__{print"_ ";* \ = * ___ ,\ & \}
    sub'___{print"_ ";* \ = * ____ ,\ & \}
    sub'____{print"_,\n"}&{_+Just}(another)->(Perl)->(Hacker)
    David Guest

Page 1 of 2 12 LastLast

Similar Threads

  1. perl and threads
    By kristoff bonne in forum PERL Modules
    Replies: 1
    Last Post: July 18th, 03:34 PM
  2. Can't pull up old threads
    By Maurice Mciver in forum ASP Components
    Replies: 0
    Last Post: September 30th, 06:09 AM
  3. Need a bit of help with threads programming
    By David Morel in forum PERL Miscellaneous
    Replies: 0
    Last Post: September 15th, 03:48 PM
  4. Using threads to obtain a value
    By Zachary P. Landau in forum Ruby
    Replies: 2
    Last Post: July 17th, 01:00 AM
  5. purpose of threads?
    By Paul Archer in forum PERL Miscellaneous
    Replies: 0
    Last Post: July 9th, 02:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139