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"; }
In reply to Re: how can I detach a thread from another or how can I set a timer for a thread?
by Khen1950fx
in thread how can I detach a thread from another or how can I set a timer for a thread?
by boeingdream
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |