Code Locking

Code locking is done at the function call level and guarantees that
a function executes entirely under the protection of a lock. The assumption
is for all access to data to be done through functions. Functions that share
data should execute under the same lock.

Some parallel
programming languages provide a construct called a monitor.
The monitor implicitly does code locking for functions that are defined within
the scope of the monitor. A monitor can also be implemented by a mutex lock.

Functions under the protection of the same mutex lock or within the
same monitor are guaranteed to execute atomically with respect to other functions
in the monitor.