Locking Files (LOCK)

It is sometimes necessary to restrict access to an entire file. As an example, you may wish to keep other processes from modifying a transaction file while an update is posting it to a summary file. This may be performed using the LOCK and UNLOCK commands. As an example:


210 OPEN (1,ERR=9500)"AP01"
220 LOCK (1,ERR=9500)

6000 REM 6000"DONE
6010 UNLOCK (1)
6020 RUN "menu"

This program assumes the presence of error handling code at line 9500. The LOCK at line 220 assures that this is the only task that may access the "AP01" file. The UNLOCK at line 6010 could be replaced with a CLOSE (1) or BEGIN to close all channels before running "menu".

LOCKing a file will, in most cases, increase performance in accessing or modifying the file. If a file is known to be used only by one process (i.e., a temporary file used for sorting or selecting records) it is always a good idea to LOCK the file for improved speed.