in reply to problem porting to threaded mode
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:
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.)tie %{$dbs[$db]}, "Thread::Shared", {module => "DB_File"}, $dbfn[$db], + O_RDONLY or die ((caller 0)[3]. " can't tie " . $dbfn[$db] . ": $!");
Update: Also don't forget to use locking where appropriate!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem porting to threaded mode
by Anonymous Monk on Jan 01, 2009 at 19:33 UTC |