[racket-dev] the preferences file under Windows
At Thu, 13 Jan 2011 17:29:15 -0500, Eli Barzilay wrote:
> 30 minutes ago, Matthew Flatt wrote:
> >
> > Unfortunately (again), the lock file has to exist alongside the data
> > file, and our existing preferences files are not accompanied by lock
> > files. It's no good assuming that you don't need the lock if there's
> > no lock file present, because the lock file might get created in
> > between the time that you try to use the lock file and the time that
> > you try to open the preferences file.
>
> Why not always use such a lock file, creating it if it's not there --
> and then you can open it once per process, and lock/unlock it for each
> read/write of the actual file.
Done (Windows only).
The `racket/file' library now provides `preferences-lock-file-mode',
which reports the style of locking being used. DrRacket, for example,
may need to use that function --- instead of testing whether the
current platform is Windows --- to determine whether it can try to
steal a lock by deleting the lock file. (As far as I know, there's no
way to steal a Windows-implemented file lock. The lock will be released
when the holding process is terminated.)
The default handling of lock errors in `get-preference' is to wait a
little while and try again. On the first failure, the handler waits
0.01 seconds, then it waits 0.02 seconds, then 0.04 seconds, then 0.08
seconds, then 0.16 seconds, and then it gives up with an exception.
This default is implemented by a `make-handle-get-preference-locked'
function provided by `racket/file'.