# LOKSER

> [HTML Version](lokser_sp.htm)

_Rewritten June 2023_

**LOKSER=\['ON' | 'OFF'\] \{,FORCE\_WRITE\}**

This directive specifies whether LOKSER is to be activated. LOKSER is a file locking scheme involving a combination of OS-level locking operations and rules governing file access. When _not_ enabled, all file operations are lock-free from the standpoint of the operating system, requiring applications to employ some other kind of A-Shell locking mechanism such as XLOCK or FLOCK in order to coordinate multi-user access.

When LOKSER is enabled:

- Random files opened in mode [RANDOM](open_random.md) are effectively opened exclusively. 

- Random files opened in mode RANDOM'FORCED are shared

- In shared mode, the [READ](read.md) statement reads without locking while [READL](read.md) reads and locks the record. [WRITE](write.md) unlocks the record after writing (requiring a prior READL), while [WRITEL](write.md) locks, writes, and then unlocks. [UNLOKR](unlokr.md) can be used to unlock a record without writing.

- Attempts to read a locked record, or to open a file in a mode that conflicts with another user already having the file open, unless the WAIT'FILE or WAIT'RECORD option is specified on the open, will generate one of the LOKSER-related errors 37 (file in use) or 38 (record in use).

- Other LOKSER-related errors include 42 (record not locked) and 44 (LOKSER queue full due to too many locks being held at once).

- ISAM sequence checking—a set of rules dictating the sequence of [ISAM File Statements](isamstatements.md)—is activated, generating ISAM error 39 on any violation.

ISAM-A operations always act as if LOKSER is enabled, i.e. they use OS-level file locking regardless of the LOKSER setting. However, they do respect the FORCE\_WRITE option if enabled.

The FORCE\_WRITE option requests that file updates be flushed to disk immediately. It is generally supported for random file write operations under Windows, and for ISAM-A operations in all environments. But it drastically slows down performance and thus is not recommended.