mutex_lock(3synch) mutex_lock(3synch)
NAME
mutex_lock - lock a mutex
SYNOPSIS
cc [options] -Kthread file
#include <synch.h>
int mutex_lock(mutex_t *mutex);
Parameters
mutex pointer to mutex to be locked
DESCRIPTION
mutex_lock locks the mutual exclusion lock (mutex) pointed to
by mutex. If mutex is locked, the calling thread is blocked
until mutex becomes available. When mutex_lock returns
successfully, the caller has locked mutex.
mutex must previously have been initialized, either by
mutex_init, or statically (see mutex_init).
From the point of view of the caller, mutex_lock is atomic:
even if interrupted by a signal or forkall [see fork(2)],
mutex_lock will not return until it holds the locked mutex.
As a consequence, if mutex_lock is interrupted, an error
indication such as EINTR is never returned to the caller.
Return Values
mutex_lock returns zero for success and an error number for
failure, as described below.
Errors
If any of the following conditions is detected, mutex_lock
returns the corresponding value:
EINVAL Invalid argument specified.
USAGE
Mutexes acquired with mutex_lock should be released with
mutex_unlock.
Warnings
If a thread exits while holding a mutex, the mutex will not be
unlocked, and other threads waiting for the mutex will wait
forever. Similarly, if a process exits while holding a
USYNC_PROCESS mutex, the mutex will not be unlocked, and other
processes or threads waiting for the mutex will wait forever.
Copyright 1994 Novell, Inc. Page 1
mutex_lock(3synch) mutex_lock(3synch)
REFERENCES
fork(2), mutex(3synch), mutex_destroy(3synch),
mutex_init(3synch), mutex_trylock(3synch),
mutex_unlock(3synch), synch(3synch)
Copyright 1994 Novell, Inc. Page 2