43.1 Advisory Locking

LibC locking is advisory; it is expected to be used by cooperating callers that want to signal section-locking status to each other to prevent I/O functions from overlapping on such sections. If you forget and access data without having first acquired a lock, there is nothing in the compiler, linker, loader, library, or operating system to stop access; the data can become corrupted.

Advisory locking differs from mandatory locking, which implicitly excludes overlapping I/O on ranges that are locked. LibC uses advisory locking almost exclusively. All advisory locks held on behalf of a virtual machine (VM) are automatically released if the VM aborts. In addition, advisory locks placed on a section of a file do not persist across a system failure or reboot.

IMPORTANT:You are responsible for deadlock detection and avoidance (see Section 43.8, Avoiding Deadlock).