4.11 File Locking



The first of these functions is dflock(C-3). Calling this function attempts to lock an open RMSfile so that other programs attempting to lock the same file will be notified that they must wait. A sample call to dflock might be:

locked = dflock (sub);

If the RMSfile was unlocked before the call to dflock, a one (1) is returned by dflock. This guarantees that all other programs attempting to lock the same RMSfile or any record within that file will be refused. If another program has already locked the specified RMSfile or has any record within the file is locked, dflock returns zero (0). At this point your program can either wait and try again, or it can notify the user of the program that the RMSfile is locked, and the user must try the operation again. Dflock always returns immediately to the calling program. It does not wait until the RMSfile is unlocked before returning.

Dflockw(C-3) is identical to dflock except that it waits until the RMSfile is locked before returning. Calling this function attempts to lock the RMSfile so that other programs attempting to lock the same file are notified that they must wait. A sample call to dflockw might be:

locked = dflockw (sub);

Normally, dflockw returns a one (1), indicating that the RMSfile is locked. However, because of some error conditions, it is possible for dflockw to return an error code of zero, so the return value should always be checked.

Dfunlock unlocks an RMSfile that has been locked by dflock or dflockw. A sample call to dfunlock might be:

unlocked = dfunlock (sub);

This allows other users to lock and access the RMSfile that has been locked by your program.