in reply to Each process needs to read the newest version of the file
Don't copy the old file to the new file, rename the old file over the new file. Then you don't need a lock and the only race condition is that a process might (depending on OS and how you do the rename) see no such file for a very short bit of time.
Update: The rename() function is atomic on many operating systems, by the way. And make sure each process doesn't open the file in a way that prevents it from being renamed/deleted/unlinked. For Unix, that isn't a problem. For Win32, unfortunately, I don't think I have a great solution at the moment -- but I'm close so let me know if you (or anyone) needs a fix for this.
- tye (but my friends call me "Tye")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: Each process needs to read the newest version of the file
by Anonymous Monk on Jan 21, 2001 at 08:02 UTC | |
by tye (Sage) on Jan 21, 2001 at 10:01 UTC |