FairCom ISAM for C

Previous Topic

Next Topic

Node Locks

In the non-server, multi-user model, when two programs attempt to update the same node, one must wait until the other has completed its update. The FairCom DB algorithm has all the necessary calls to the locking routines coded into place.

Because of the robust nature of the FairCom DB B-Tree algorithm, it is not necessary for a program that is merely searching (i.e., not updating) the index file to be locked out of any node, even if the node is currently being updated by another program. This leads to a special case: if only one “user” in a non-server, multi-user system is allowed to update the index files, then it is not necessary to actually place locks on nodes which are being updated.

Another important aspect of the special B-Tree algorithm used in FairCom DB is that competing node locks are guaranteed not to cause a deadlock situation. Therefore, the node lock routines can ignore the problems associated with deadlocks.

To use the FairCom DB index files in a non-server, multi-user system, the following steps must be taken:

  • Set the disk protocol in ctoptn.h to FPUTFGET; and
  • If more than one user is allowed to update the index structures at the same time, the node lock routines (LOCK() and UNLOCK()) in ctslck_a.c must be coded to access the operating systems locking protocols.

For most environments, these routines have already been implemented. If your operating system/compiler environment is one for which FairCom DB LOCK() and UNLOCK() have not been implemented, and if you intend to run in the Standalone Multi-user mode of operation, then examine the compiler’s run-time library documentation to determine how locks are implemented. Also, examine the implementation of locks in the ctslck_a.c module supplied for the Microsoft C compilers and the ctslck_a.c supplied for Unix system.

Note: The most significant feature of LOCK() is that it loops until it acquires a node lock. The looping is permitted since the index routines are guaranteed deadlock free.