in reply to how to share array of hashes among several threads?
Did you see Thread::Queue ?
If you want a fast, CPU-efficient, bug-free way to do this, another common way is to simply use a database.
Fortunately there are many lightweight and even Pure Perl database packages out there which present themselves in a number of useful ways to make this a relatively easy undertaking. That way, all the "hard" problems of consistency are generally solved for you.
Have a play with a module like DB_File or SDBM_File to get a feel for how you can use this, then try it in concert with MLDBM. As they don't provide a queue for you, you'll have to make a "lock" key that you acquire before updates and release afterwards to prevent concurrent access from wedging your database.
$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";
|
|---|