chickadee » dot-locking » obtain-dot-lock

(obtain-dot-lock file-name [interval retry-number stale-time])procedure

Tries to obtain the lock for file-name. If the file is already locked, the thread sleeps for interval seconds (default is 1) before it retries. If the lock cannot be obtained after retry-number attempts, the procedure returns #f, otherwise #t. The default value of retry-number is #f which corresponds to an infinite number of retries.

If stale-time is non-#f, it specifies the minimum age a lock may have (in seconds) before it is considered stale. Obtain-dot-lock attempts to delete stale locks. If it was successful obtaining a lock after breaking it, obtain-dot-lock returns 'broken. If stale-time is #f, obtain-dot-lock never considers a lock stale. The default for stale-time is 300.

Note that it is possible that obtain-dot-lock breaks a lock but nevertheless fails to obtain it otherwise. If it is necessary to handle this case specially, use break-dot-lock directly (see below) rather than specifying a non-#f stale-time