in reply to Easy shared data for forked processes?

Yuval Kogman came up with a KiokuDB solution:
#!/usr/bin/perl -w use strict; use warnings; use Time::HiRes qw(sleep); use Test::More 'no_plan'; { package Simple; use Moose; has 'nums' => ( isa => 'ArrayRef[Int]', is => 'rw', default => sub { [] }, ); } use KiokuDB; use Parallel::ForkManager; my @in = 1 .. 50; our @out; my $pm = new Parallel::ForkManager(5); my $dir = KiokuDB->connect( "dbi:SQLite:dbname=kiokudb_tutorial.db", c +reate => 1 ); my ( $id ) = $dir->txn_do( scope => 1, body => sub { $dir->insert( Sim +ple->new ) } ); warn "id: $id"; for my $link (@in) { $pm->start and next; retry: { eval { $dir->txn_do( scope => 1, body => sub { my $obj = $dir->lookup($id); push @{ $obj->nums }, $link; $dir->update($obj); } ); }; if ( $@ ) { warn "$$ failed to commit, sleeping for random interval an +d retrying"; my $i = rand(0.1); sleep $i; redo retry; } else { warn "$$ successfully comitted"; } }; $pm->finish; } $pm->wait_all_children; $dir->txn_do( scope => 1, body => sub { my $obj = $dir->lookup($id); is( scalar(@{ $obj->nums }), scalar(@in), "update count is correct +" ); warn $obj->dump; });