For what it's worth, in my experience/experiments, using DB_File with the lastest version of the Berkeley DB(4x), there really isn't any need to do any sort of locking when all you want is to read.
The Berkeley DB mechanisms take care of any potential data corruption.
In the example below, run #1 and then #2 while #1 is still running (preferably in 2 separate shells -- simultaneous)
# 1
perl -MFcntl -MDB_File -e"tie%a,'DB_File','rat.test',O_CREAT|O_RDWR or
+ die $!;for(1..1_000){select undef,undef,undef,.01;$a{a}++;}"
# 2
perl -MFcntl -MDB_File -e"tie%a,'DB_File','rat.test',O_RDONLY or die $
+!;warn $a{a}"
When you first run #1, and then #2 ( while #1 is still running),
#2 will yield Warning: something's wrong at -e line 1.
every time you invoke it, whilst #1 is still running.
After #1 is finished running, then run #2 again, and it will yield 1000 at -e line 1.
In my programs, I freely tie a DB_File for O_RDONLY, but for O_RDWR, I use a flocking mechanism like DB_File::Lock.
MJD says you
can't just make shit up and expect the computer to know what you mean, retardo!
** The Third rule of perl club is a statement of fact: pod is sexy.
|
| [reply] [d/l] |