Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: How to apply flock

by PodMaster (Abbot)
on Nov 24, 2002 at 12:23 UTC ( [id://215493]=note: print w/replies, xml ) Need Help??


in reply to Re: How to apply flock
in thread How to apply flock

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://215493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-16 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found