The most obvious question is why you want to shift to Apache2 threaded MPM and perl ithreads. It seems like a source of trouble to me with no obvious benefits.

Anyways you are trying to do it, so what is going wrong in your attempts? Well the first problem was that {} can't be shared. You can wrap it with shared or shared_clone to solve that problem, and you did. But then you have a situation where you have declared a shared variable and then try to tie it. But as Liz says in Things you need to know before programming Perl ithreads, sharing already works through a tie so you can't tie a shared variable. So your dbs continue to look like empty hashes after the tie. Then you got rid of the share and ran into the fact that DB_File is a C-level library that was never designed to be thread safe..

How then can you solve this? Your best bet i Thread::Shared. From the documentation you should not share the variables and instead write something like this:

tie %{$dbs[$db]}, "Thread::Shared", {module => "DB_File"}, $dbfn[$db], + O_RDONLY or die ((caller 0)[3]. " can't tie " . $dbfn[$db] . ": $!");
Alternately in the unshared version you can try to replace DB_File with something else. BerkeleyDB is a more sophisticated version of the same, but I doubt it is thread-safe. The pure Perl DBM::Deep is more promising. It should be easy to do a one-time copy from one format to the other. I'd be somewhat concerned about whether seeks on the database file in different threads could interfere with each other, but you can test that fairly easily and it probably works. (I'm paranoid though, and would test it.)

Update: Also don't forget to use locking where appropriate!


In reply to Re: problem porting to threaded mode by tilly
in thread problem porting to threaded mode by cmac

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.