Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: File Locking revisitedby paulbort (Hermit) |
on Dec 01, 2004 at 21:09 UTC ( [id://411572]=note: print w/replies, xml ) | Need Help?? |
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!
In Section
Seekers of Perl Wisdom
|
|