in reply to how can I detach a thread from another or how can I set a timer for a thread?
Delete that line. Then on line #12 add detach:$thr_1->detach();
The script:$thr_2 = threads->create('func_thr_2')->detach;
#!/usr/bin/perl use strict; use warnings; use threads; my $thr_1; my $thr_2; my $timer = 3; my $res; $thr_1 = threads->new('func_thr_1'); $thr_2 = threads->create('func_thr_2')->detach; $res = $thr_1->join(); print "exit code is: $res\n"; print "\nend\n"; sub func_thr_1 { my $cc = 0; print "thread 1 is running\n"; while ($cc <= 10) { print "cout is $cc\n"; sleep 1; $cc++; } return 'success'; } sub func_thr_2 { while ($timer >= 0) { $timer--; sleep 1; } print "\nTime up\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how can I detach a thread from another or how can I set a timer for a thread?
by boeingdream (Novice) on Nov 11, 2011 at 06:14 UTC | |
by zentara (Cardinal) on Nov 11, 2011 at 10:17 UTC | |
by locked_user sundialsvc4 (Abbot) on Nov 14, 2011 at 14:44 UTC | |
by boeingdream (Novice) on Nov 15, 2011 at 10:51 UTC | |
by zentara (Cardinal) on Nov 15, 2011 at 11:13 UTC | |
by Anonymous Monk on Nov 15, 2011 at 11:15 UTC |