Skip to content

Modern Fs FileLock Acquire

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Filesystem › Filesystem Library › FileLock.Acquire

FileLock.Acquire

Takes a lock on a file that cooperating programs share, waiting up to a timeout.

Syntax

FileLock.Acquire( p [, exclusive ] [, timeoutMs ] )

Notes

  • FsResultBool

Examples

#import "std/fs"
using fs

dim td as FsResultUStr = CreateTempDir( "fbdoc" )
dim as ustring dir_ = td.Value( )
dim as ustring p = PathJoin( dir_, "f.txt" )
WriteAllText( p, "hello" )

dim lk as FileLock

'' Exclusive by default. The timeout is in milliseconds; -1 waits
'' forever, 0 tries once and gives up.
print lk.Acquire( p ).IsOk( )             '' true
print lk.IsHeld( )                         '' true

lk.Release( )

'' ADVISORY BETWEEN PROCESSES USING THIS API -- it does not stop a
'' program that simply opens the file and writes
print lk.Acquire( p, true, 0 ).IsOk( )    '' true -- free again
lk.Release( )

RemoveDirAll( dir_ )

Library: Filesystem Library
Category: Filesystem
Documented under: Locking, Mapping And Watching

Clone this wiki locally