lang • lock


Stream = LOCK Path

Use the specified Path to create a system-global lock.

If the specified file is already locked by another process, then the command fails.

Beware that the locked file is emptied! So never use a file whose contents is important.

Unlock the file with the UNLOCK instruction.

Keep a reference on the stream object returned by LOCK, because as soon as the stream object is freed, it is closed and the lock is released.


Dim hLock As Stream
' Try to acquire the lock
Try hLock = Lock "~/my-lock"
If Error Then
  Print "Locked is already acquired. Try again later."
' File is locked, you can do the job now!
' Do not forget to release the lock
Unlock hLock


Since 3.6

Stream = LOCK Path WAIT Delay

Try to lock a file during a specified delay until it succeeds.

Delay is expressed in seconds (it can be a floating-point number).

If the delay elapses before the lock is acquired, the command fails

See also