in reply to Re^2: File Locking revisited
in thread File Locking revisited
Regarding this part of the OP:
Let's say I have a system where more than one process will try to grab a pair of files (two associated files), read it/them, copy it/them elsewhere, and delete the originals. I want only one copy of the originals to be floating around. The initial solution wasget handles,
lock,
copy,
unlock,
unlink.
If I get what you're describing, multiple processes can be trying to access either of two files at any time, and will normally want to "open / read / close / make a copy elsewhere / unlink the original" on each file in succession.
With a semaphore file, it would look like this:
So long as all the competing processes are set to use the same semaphore file, this will assure that only one process at a time can do anything at all with the two target data files.get lock on semaphore file for (file1, file2) { open read and copy close unlink } release semaphore file lock
|
|---|