An idea I have often toyed with in such situations is to daemonise the data management. So one process does nothing but insert, update, delete and fetch from the structure. The main program does an IPC::Open2 or IPC::Open3 on the data management process and the threads or forks from the main program share the filehandles to communicate with the data management process but not its memory. For example
# data manager (short separate program) while( <> ) { chomp; my ( $command, $value, $address ) = split /\t/; if ( $command eq 'insert' or $command eq 'update' ) { eval( "$address = $value;" ); } elsif( $command eq 'delete' ) { delete $$address; } else{ eval "print \$address;" } } # and the main program: use IPC::Open2; my $pid = open2 my $wh, my $rh, 'DataManager.pl'; ... print $wh "insert\t\"fred\"\t" . '$deepthing01{ fred }{ bert }{ pete } +[99]'; ...

One world, one people


In reply to Re: Sharing large data structures between threads by anonymized user 468275
in thread Sharing large data structures between threads by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.