Sounds like a good use of the optimistic locking technique. Create a sister file containing an integer/timestamp or the timestamp on the file well call this the version file. The first thing all instances do is load the version, and the data file. When an update is about to occur, read the version file and compare with what was read the first time. If they match you know you nobody has written to the file, set a new time or increment the version. if they do not match, get the new version, and re-read the data updates. So now if (when) a crash happens, no need to worry about incorrect flag settings. All old instances will be out of date and new instances will have access to write. Since there could be that millisecond between reads and writes of the version file, you will run into version conflicts. Same problem with reading max(parent key id) on a read database table instead of using an auto increment or sequence generator. Where one process controls who has write access.
A variation of the the technique would be to create individual process files in a central location and using the OS, create individual files and using them to determine last updated time stamp, getting a directory and sorting on date-time descending. To be real slick about it have a process which manages the write control. Listener/Sender type application like IM or Chat. ACK and NAK.. Doh.. I babble a lot.... ----- Original Message ---- From: Cosmin Prund <[EMAIL PROTECTED]> To: Borland's Delphi Discussion List <delphi@elists.org> Sent: Tuesday, March 20, 2007 5:28:27 AM Subject: Re: File/record locking Ross Levis wrote: > Hi Tony > > I considered a flag in the file, but there will be a problem if there is > a power cut or PC crash and the flag is left in the file, and everyone > is locked out. It will need some manual utility to reset it. > > Set a "time-out" period on the flag so the flag would automatically revert to "0" if the power failed or the application crashed / hanged. You'll then need a way to keep clocks synchronized across your network. You might also place the file lock into a separate file so you can use OS-provided locking functions on that. This way you can open the main file without any kind of sharing protection, but when you actually need to write to the file, you try locking the lock file! If the power fails the lock will be freed. _______________________________________________ Delphi mailing list -> Delphi@elists.org http://www.elists.org/mailman/listinfo/delphi _______________________________________________ Delphi mailing list -> Delphi@elists.org http://www.elists.org/mailman/listinfo/delphi