Re: Parallel trigger of different subs
by karlgoethebier (Abbot) on Jan 02, 2018 at 11:51 UTC
|
#!/usr/bin/env perl
use strict;
use warnings;
use threads;
use MCE::Hobo;
use Data::Dump;
use feature qw(say);
use constant AMOUNT => 0;
my $shared = MCE::Shared->hash();
my $nose = MCE::Hobo->new( \&nose, "cuke" );
my $foo = MCE::Hobo->new( \&foo, "bar" );
# $nose->join;
# $foo->join;
MCE::Hobo->wait_all();
my $hash_ref = $shared->export;
dd $hash_ref;
say $shared->{nose};
say $shared->{foo};
sub nose {
sleep AMOUNT;
$shared->set( nose => shift );
}
sub foo {
sleep AMOUNT;
$shared->set( foo => shift );
}
__END__
Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help
| [reply] [d/l] [select] |
Re: Parallel trigger of different subs
by jahero (Pilgrim) on Jan 02, 2018 at 08:04 UTC
|
| [reply] |
Re: Parallel trigger of different subs
by BrowserUk (Patriarch) on Jan 02, 2018 at 12:22 UTC
|
#!perl -slw
use strict;
use threads;
sub one {
select('','','',rand(0.01)), print 'one' while 1;
}
sub two {
select('','','',rand(0.01)), print 'two' while 2;
}
async \&one;
two;
Doing something useful with it requires a little more thought.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
Suck that fhit
| [reply] [d/l] |
Re: Parallel trigger of different subs
by karlgoethebier (Abbot) on Jan 02, 2018 at 17:06 UTC
|
| [reply] [d/l] |
Re: Parallel trigger of different subs
by thanos1983 (Parson) on Jan 02, 2018 at 19:39 UTC
|
Hello Anonymous Monk,
In reply to your merged thread Running 2 different subs simultaneously. I am not sure exactly why the replies of the fellow Monks did not cover your question but maybe the use of Parallel::Simple a really simple module in parallel processes will help you to understand that your question is answered already.
Sample of code:
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Parallel::Simple qw(prun);
sub myFooSub {
say "$$ foo 'clear bgp'";
}
sub myBarSub {
say "$$ bar 'clear ospf'";
}
# style 2: named code blocks (like the Benchmark module)
prun(
foo => \&myFooSub,
bar => \&myBarSub,
) or die( Parallel::Simple::errplus()
);
__END__
$ perl test.pl
21120 foo 'clear bgp'
21121 bar 'clear ospf'
Hope this helps, BR.
Seeking for Perl wisdom...on the process of learning...not there...yet!
| [reply] [d/l] [select] |
Re: Parallel trigger of different subs
by Anonymous Monk on Jan 02, 2018 at 13:13 UTC
|
If you describe your overall goal ... your particular use-case ... more-completely at a place like this, you will get a better answer. Always remember that the CPAN search site is literally stuffed with solutions that you can simply take off-the-shelf and use in your projects – and some Monk somewhere already knows all about the good ones. If you are doing "a thing that has already been done," such as in this case, you can be certain that CPAN will be able to take you very far along your path, very fast. Therefore, always begin there ... and, by asking conceptual questions here. | [reply] |
Running 2 different subs simultaneously
by Anonymous Monk on Jan 02, 2018 at 17:59 UTC
|
Sorry, i posted this thread earlier with the Title " Parallel trigger of different sub". I was not specific there. Let me be more specific in this thread. My customer wants to run 2 different subs together.
just for example. Sub A does "clear bgp" and Sub B does "clear ospf " and he don't want to add all the steps in Sub B to Sub A (and run only Sub A). Both should be different entities . But, he wants to execute both "clear bgp" and "clear ospf" at the same time (not one after the other, should be parallel). This is just an example
| [reply] |
|
| [reply] [d/l] [select] |