Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Flock Updating Counter

by jreades (Friar)
on Dec 06, 2002 at 11:29 UTC ( #218038=note: print w/ replies, xml ) Need Help??


in reply to Flock Updating Counter

There are also a number of locking modules that might help you (if this snippet is part of a larger script and not something quick and dirty):

http://search.cpan.org/search?query=File+locking&mode=all

LockFile::Simple especially can be quite handy -- it's very lightweight, however, and on the whole a database is a better way to handle this type of thing (unless the overhead is unecessary).

But the general answer is that you want to hold on to the lock until you're done writing out the new id and not grab one, release it after a read, then grab it again. Also, if you're using flock() it seems like you want an exclusive lock since you don't want another process to read the id value until it has been updated.


Comment on Re: Flock Updating Counter

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (15)
As of 2015-07-06 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls