Lock and Unlock Methods

You can make a key in a space read-only by locking it. When a key is locked, only the lock owner has the ability to modify the data that is stored with that key. Locking is enforced regardless of the presence or not of a record for the key being locked.

The owner of the lock is either the thread that created it, or the process. You can define this lock ownership scope when acquiring the lock. Locks are automatically cleared if the member that created them leaves the metaspace.

Locking protects the data stored in the space, you can even lock an empty key to prevent anyone else from inserting a record there. Any operation to modify the key (put, take, and so on) will be denied if it is issued outside of the lock's scope. It is also possible to make those operations (not just other attempts to lock) block for a period of time using the space's LockWait attribute.

The lock function automatically returns the tuple that was stored at the key (or null is there was none) upon lock acquisition. If the lock could not be acquired then an exception is thrown (or LOCKED is returned in the status in C).

Tip: You can optimize performance by combining locking and unlocking with many space operations using options.
Related reference