anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:
In my plan, catch_CtrlC will first receive the signal and forward it to all thread one by one. For every thread, the trExit will do sth. and exit. I guess I'm using in a wrong way, righ?#/usr/bin/perl -w use strict; use warnings; use threads; use threads::shared; my @thrList; my $count=1; share $count; $SIG{INT} = \&catch_CtrlC; &main; sub main { my $counter = 3; while($counter) { $counter--; my $thrHandle = threads->create(\&thrdfun); push @thrList, $thrHandle; } print " waiting \n"; foreach(@thrList){ $_->join(); } } sub thrdfun { $SIG{INT} = \&trExit; print "thrdfun: $count \n"; $count++; while(1){ } exit; } sub trExit { print " exit \n"; threads->exit(); } sub catch_CtrlC { print " catch_CtrlC \n"; foreach(@thrList){ $_->kill("INT"); } exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: about THREAD SIGNALLING
by Khen1950fx (Canon) on Apr 23, 2013 at 06:26 UTC | |
by anaconda_wly (Scribe) on Apr 23, 2013 at 06:55 UTC | |
by Khen1950fx (Canon) on Apr 23, 2013 at 08:26 UTC | |
by anaconda_wly (Scribe) on Apr 23, 2013 at 08:44 UTC | |
by anaconda_wly (Scribe) on Apr 23, 2013 at 07:15 UTC |