Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: File Locking revisited

by paulbort (Hermit)
on Dec 01, 2004 at 21:09 UTC ( [id://411572]=note: print w/replies, xml ) Need Help??


in reply to File Locking revisited

Other Monks have already suggested using a third file, and I agree that what is missing here is a resource, but I would be inclined to not use file locking at all. If you consider this a serialization problem instead of a contention problem, a different solution presents itself: Funnel all requests for the files to be copied to a second program, which can deal with the requests in turn. Maybe this funnel is done by appending to a text file (Which the OS will usually keep atomic), or writing records to a queue table in a database, or using a socket.

Then all the second program does is watch for a signal to do the copy, and act on that. Since it is the only one doing the copy, no contention issue. If you want to discard some copy requests based on other criteria (can't copy within one minute of last copy, etc.) that becomes easy.

This also has other advantages, in that it can handle copy requests from programs that don't use Perl's locking semantics, can log all of the copy requests, etc.

--
Spring: Forces, Coiled Again!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-20 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found