in reply to Perl seg fault while joining threads
So is there a way to tell perl not to copy a specific variable while creating new threads ?
I don't have Net::AMQP::RabbitMQ, so this is untested, but if your description is accurate, it ought to work.
Just re-structure your code slightly:
#!/usr/bin/perl use Cwd qw/realpath/; use File::Basename qw/dirname/; use lib 'lib'; use threads; use threads::shared; use initial; my @threads = (); my $run :shared = 1; sub proc1 { while($run){ sleep(1); print "I am child thread 1 \n" } } sub proc2 { while($run){ sleep(1); print "I am child thread 2 \n"; } } threads->create(\&proc1); threads->create(\&proc2); my $init = load initial($name); $SIG{'TERM'} = sub { $run = 0; }; while($run){ sleep(1); print "I am main thread\n"; } $_->join() for threads->list();
In general, it is better to start your threads before you create/allocate anything that is only used by your main thread.
See threads: spawn early to avoid the crush. for more details.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl seg fault while joining threads
by kamrul (Acolyte) on Jul 07, 2015 at 22:46 UTC | |
by BrowserUk (Patriarch) on Jul 08, 2015 at 07:16 UTC | |
by Myrddin Wyllt (Hermit) on Jul 08, 2015 at 01:32 UTC |