Greetings unto ye who dwell within The Monastic Perly Gates.
It behoves me to humbly submit veneration to pave my request for your manifold threaded blessings.
I, possessing the skill of just a babe, am only beginning my pilgrimage along the path to scriptic enlightenment.
I have had a vision...of the many process paths one can travel, likened unto a multiverse with a portal at the end of child process run-time, such as can bring together once again in a glorious familial union all the scalar objects of my data affection.
But alas, the children, having left the Edenic memory space, have begun to murder each other...and so I have decided to confuse their number bases to facilitate coexistence via the spreading of their names across file allocation table space.
Yet still they sub-routinely fight over scalar object control.
And lo, I see no answer, but for me to go down into the realm of my children to understand them, be like one of them, and see how they are treating each other's memory pool.
For that, I beseech ye: will ye abide in hopefully not-so-longsuffering to see peace amongst my process children?
As by now you may have prophesied, here is the scripture reading for today...
taken from the NewTransmogrified Version:
(Edit1:
(for the benefit of fellow perlgrims) added
the_main_reason(); as per the Monastic Guidance of
choroba.
#!/usr/bin/perl
use 5.24.0; # Book, Chapter and Verse
use strict; # the First Commandment
use warnings; # the Second Commandment
use Digest::MD5 qw(md5_hex); # identity and volition
use Math::Prime::Util ':all'; # the Tempter
# provides 'todigitstring' and 'fromdigits'
# I believe this is the cause - at line 132 in GMP.pm: '_GMP_destr
+oy();'
use Parallel::ForkManager; # the Family Unit
my $children = 5;
my @children = ("Cain","Abel","Seth","Noah","Shem");
my $birthorder = 0;
my $family = Parallel::ForkManager->new($children);
the_main_reason();
sub the_main_reason {
print "Forming $children children.\n";
BEGET:
foreach my $child (@children) {
$birthorder++;
print "Today, I have begotten child $birthorder as $child\n";
$family->start($child) and next BEGET;
if ($child =~ m/cain/i) {
the_task_I_gave_cain_to_do("Cain");
} elsif ($child =~ m/abel/i) {
the_task_I_gave_abel_to_do("Abel");
} elsif ($child =~ m/seth/i) {
the_task_I_gave_seth_to_do("Seth");
} elsif ($child =~ m/noah/i) {
the_task_I_gave_noah_to_do("Noah");
} elsif ($child =~ m/shem/i) {
the_task_I_gave_shem_to_do("Shem");
}
# enable some prayer
print "\$family->finish on child $child\n";
$family->finish(0);
}
# my longsuffering
print "\$family->wait_all_children() is waiting...\n";
$family->wait_all_children();
} # the_main_reason
exit;
##########################################################
# priestly duties
##########################################################
sub the_task_I_gave_cain_to_do {
my $worker = shift;
print "$worker is working.\n";
my $harvest; # A large harvest offering from Cain
my $unique_offering; # so we know whose and what transgressions th
+is offering covers
my %items_to_offer;
for (1..100000) {
$items_to_offer{$_} = "Something $worker will burn on the alte
+r: " . rand();
}
foreach my $item (sort keys %items_to_offer) {
$harvest .= $items_to_offer{$item} . "\n";
}
# here are 3 attempts at obtaining salvation for the child via an
+acceptable sacrifice
# needless to say, they can only provide temporary atonement, in t
+he end death comes to the child
# first offering attempt - fruit - seems acceptable, but fails to
+atone in the end
$unique_offering = todigitstring(fromdigits(md5_hex($harvest), 16)
+, 36);
# free to wrong pool - child ends up in the lake of fire
# OR
# second offering attempt - grain - same judgement in the end as a
+bove
# $unique_offering = sub{todigitstring(fromdigits(md5_hex($harvest)
+, 16), 36); return;};
# free to wrong pool - child ends up in the lake of fire down
+this path too
# OR
# third offering attempt does not even make it into liturgically a
+cceptable syntax
# $unique_offering = sub{lock(todigitstring(fromdigits(md5_hex($har
+vest), 16), 36); return;)};
# the $harvest is 'put in the storehouse' and is uniquely identifi
+ed
# against the offerer with $unique_offering in the book of data li
+fe
return;
}
sub the_task_I_gave_abel_to_do {
my $worker = shift;
print "$worker is working.\n";
my $harvest;
my $unique_offering;
my %items_to_offer;
for (1..100000) {
$items_to_offer{$_} = "Something $worker will burn on the alte
+r: " . rand();
}
foreach my $item (sort keys %items_to_offer) {
$harvest .= $items_to_offer{$item} . "\n";
}
$unique_offering = todigitstring(fromdigits(md5_hex($harvest), 16)
+, 36);
# OR
# $unique_offering = sub{todigitstring(fromdigits(md5_hex($harvest)
+, 16), 36); return;};
# OR
# $unique_offering = sub{lock(todigitstring(fromdigits(md5_hex($har
+vest), 16), 36); return;)};
# the tithe is brought to the storehouse here
return;
}
sub the_task_I_gave_seth_to_do {
my $worker = shift;
print "$worker is working.\n";
my $harvest;
my $unique_offering;
my %items_to_offer;
for (1..100000) {
$items_to_offer{$_} = "Something $worker will burn on the alte
+r: " . rand();
}
foreach my $item (sort keys %items_to_offer) {
$harvest .= $items_to_offer{$item} . "\n";
}
$unique_offering = todigitstring(fromdigits(md5_hex($harvest), 16)
+, 36);
# OR
# $unique_offering = sub{todigitstring(fromdigits(md5_hex($harvest)
+, 16), 36); return;};
# OR
# $unique_offering = sub{lock(todigitstring(fromdigits(md5_hex($har
+vest), 16), 36); return;)};
# the tithe is brought to the storehouse here
return;
}
sub the_task_I_gave_noah_to_do {
my $worker = shift;
print "$worker is working.\n";
my $harvest;
my $unique_offering;
my %items_to_offer;
for (1..100000) {
$items_to_offer{$_} = "Something $worker will burn on the alte
+r: " . rand();
}
foreach my $item (sort keys %items_to_offer) {
$harvest .= $items_to_offer{$item} . "\n";
}
$unique_offering = todigitstring(fromdigits(md5_hex($harvest), 16)
+, 36);
# OR
# $unique_offering = sub{todigitstring(fromdigits(md5_hex($harvest)
+, 16), 36); return;};
# OR
# $unique_offering = sub{lock(todigitstring(fromdigits(md5_hex($har
+vest), 16), 36); return;)};
# the tithe is brought to the storehouse here
return;
}
sub the_task_I_gave_shem_to_do {
my $worker = shift;
print "$worker is working.\n";
my $harvest;
my $unique_offering;
my %items_to_offer;
for (1..100000) {
$items_to_offer{$_} = "Something $worker will burn on the alte
+r: " . rand();
}
foreach my $item (sort keys %items_to_offer) {
$harvest .= $items_to_offer{$item} . "\n";
}
$unique_offering = todigitstring(fromdigits(md5_hex($harvest), 16)
+, 36);
# OR
# $unique_offering = sub{todigitstring(fromdigits(md5_hex($harvest)
+, 16), 36); return;};
# OR
# $unique_offering = sub{lock(todigitstring(fromdigits(md5_hex($har
+vest), 16), 36); return;)};
# the tithe is brought to the storehouse here
return;
}
Below is the 'real' output from a parallel universe...I know, a bad pun:
("c:12" is just an optional MAX_CHILD argument)
Some inter-verse translation:
Running 5 threads. => print "Forming $children children.\n";
Thread N running for XX => print "Today, I have begotten child $birthorder as $child\n";
Starting XX under process id -NNNN => print "$worker is working.\n";
I thought I was looking through the Windows of seven (oh, boy, that's a bad one!), but I think they are Windows of leaven and hell...
user@computer C:\Users\user
>perl C:\Users\user\eclipse-workspace\Crunchy\Generate_Mergatroidians.
+pl c:12
Running script: C:\Users\user\eclipse-workspace\Crunchy\Generate_Merga
+troidians.pl
Running 5 threads.
Thread 1 running for PR
Starting PR under process id -4336
Thread 2 running for PT
Starting PT under process id -4140
Thread 3 running for SS
Starting SS under process id -1976
Thread 4 running for AR
Starting AR under process id -2540
Thread 5 running for FO
Starting FO under process id -1352
$obfuscation->wait_all_children() is waiting...
$obfuscation->finish on child PT
Free to wrong pool 34817a0 not 5e7460 at C:/Perl64/lib/Math/Prime/Util
+/GMP.pm line 132.
user@computer C:\Users\user
>
The short of it is this:
All children appear to play 'together' nicely until the first one has finished and wants to go home to mummy...then it kill's all children and someone goes into the lake of fire (totally the wrong pool).
Here is The Question: how can I call a non-threadsafe module sub from multiple parallel spawned child threads in a way that none of them, or the called module, cause this amnesia?
The second is likened unto the first: do I need to lock these calls, and if so how do I lock them?
I have searched heaven and hell for the answer, but Google, though laughing in the stand, is not confessing...
...in faithful gratitude...