Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: File Locking

by Anonymous Monk
on May 07, 2008 at 21:58 UTC ( #685336=note: print w/replies, xml ) Need Help??


in reply to Re: Re: File Locking
in thread File Locking

If you're pretty sure the friend is not on the list, then locking the file exclusive for the entire operation is a good idea.

However, locking the file in LOCK_EX (instead of LOCK_SH) will limit the concurrency of the operation to 1. So if you just want to check if they are (not) on the list, a shared lock will scale better. Check again after you get an exclusive lock, to avoid race conditions. (For even better scalability, use a database.)

Replies are listed 'Best First'.
Re^4: File Locking
by Anonymous Monk on Mar 23, 2011 at 13:15 UTC

    OPTIMIST (likely to find the item in the list): Start with a shared lock, and without unlocking, "promote" to an exclusive lock once not found; make sure there is a timer on the attempt to prevent a deadlock, and if the timer goes off then unlock and retry from the top.

    PESSIMIST (unlikely to find the item in the list): Use the exclusive lock from the beginning.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://685336]
help
Chatterbox?
Veltro is a weirdo, obsessed with whitespace
[marto]: to use the word "obsession" when so few people have said so little about it is grasping at staws
marto wishes tye was around, he's so much better at this sort of thing
usemodperl likes tye!
usemodperl tye  too
[choroba]: Re^3: LiBXML: New markup while preserving earlier tags? would benefit from a couple of test cases
usemodperl meant tye 
usemodperl pokes Veltro with line noise
usemodperl will try to make better shapes with his line noise, like a camel, or boobs, then it will be called "clever" :-)
Veltro Veltro translates line noise. It spells JAPH,

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2018-06-24 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (126 votes). Check out past polls.

    Notices?