File Locking

This is a mechanism that locks a file during editing in order to protect it from getting corrupted. There are, broadly, two types of locks in computing, exclusive locks and advisory locks. Corruption would be as a consequence of a race condition where two or more proceses or users are attempting to update a single record or file at the same time. It would, then, not be possible to verify the authenticity of the file or record, whoever user or whichever process wins.

Example of Exclusive Lock:

Two ATM cards are issued for the same account. Both ATM cards are inserted into two ATM machines in different geographical locations. Without a lock, both ATMs would read the account balance and show a copy of it to the card holders. The two account holders would, then, be in a position to withdraw funds respectively. However, after, say card holder A has withdrawn their cash, the ATM would update the record to reflect the new account balance. Then, card holder B would do the same thing using a stale copy of the actual account balance leading to the update by card holder A getting lost. To protect against this, locks are, then, able to serialize the updates and ensure that each update is to the most current record.

Example of Advisory Lock:

Various users or processes working on a project are required to update a particular file in order to ensure that it captures the current state of the project and ensure decisions are made in a timely manner. The file is shared and each team leader updates the particular segment that relates to them. This, then, means that the segment that each user or process is updating is locked during that update but not the entire file. The underlying system would, then, be required to protect against errors during read, write or delete which would typically require that the editing process or user does not get a cached copy of the file but does the editing directly from the server.

Leave a reply