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.
|
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.