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.

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.

Example

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."
  RETURN
ENDIF
' File is locked, you can do the job now!
...
' Do not forget to release the lock
UNLOCK hLock

LOCK WAIT

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