.th K_lock II 4/21/86
.sh NAME
K_lock \- lock a segment for exclusive use
.sh "MODULA SYNOPSIS"
.nf
 CONST seg: seg_des;
 CONST tout: cardinal;
 VAR status: K_err_num;
 ...
 status := NK_lock(seg, tout);
.sp
.sh "C SYNOPSIS"
 seg_des seg;
 cardinal tout;
 int status;
 ...
 status = K_lock(seg, tout);
.sp
.fi
.sh DESCRIPTION
K_lock is a means by which a process may temporarily gain exclusive
access to a segment.  The calling process must have write access to the
specified segment.  The effect of the call is such that any other
process attempting to K_lock the same segment will block until the
segment has been K_unlocked by the original locking process.
.s3
Upon return from the K_lock system call, either of two conditions will
hold.  Either the segment will have been successfully locked by the
calling process, or the specified number of clock ticks will have
passed.  When the timeout period specified by tout is zero, K_lock
always returns immediately.  The value returned by K_lock determines
whether or not the segment was successfully locked.
.s3
Note that the exclusion afforded by the K_lock system call is
cooperative.  Any process may read or write the segment while it is
locked.  It is by bracketing critical sections of processes sharing
access to segments with the K_lock and K_unlock system calls that
correct synchronization may be achieved.
.s3
This call has no effect if the segment is currently locked by the
calling process.  A process is not allowed to fork when it has a
segment locked for exclusive access (similar to exclusive open).
.sh EXCEPTIONS
.s3
.lp 22 15
XnSgDes		Not a segment designator:  This number is outside the set of
segment designators.
.lp 22 15
XbSgDes		Bad segment designator:  this segment designator is inactive.
.lp 22 15
XnotWritable	Not writable:  cannot lock a segment without write access.
.lp 22 15
XncnDo		Cannot do:  global resource exhaustion.
.lp 22 15
Xtimeout	Timeout:  wasn't able to lock segment before end of
specified timeout period.
.i0
.sh "SEE ALSO"
K_unlock(II)
