mutex_init(3synch) mutex_init(3synch)
NAME
mutex_init - initialize a mutex
SYNOPSIS
cc [options] -Kthread file
#include <synch.h>
int mutex_init(mutex_t *mutex, int type, void *arg);
Parameters
mutex pointer to mutex to be initialized
type USYNC_THREAD or USYNC_PROCESS
arg NULL (reserved for future use)
DESCRIPTION
mutex_init initializes the mutual exclusion lock (mutex)
pointed to by mutex to be of type type and in the unlocked
state. Once initialized, the mutex can be used any number of
times without being re-initialized.
mutex Parameter
mutex points to the mutex to be initialized.
type Parameter
type can be set to one of the following values:
USYNC_THREAD Initialize the mutex for threads within the
current process.
USYNC_PROCESS Initialize the mutex for threads across
processes.
arg Parameter
arg should be set to NULL. It is not currently used, but is
reserved for future use.
Static Mutex Initialization
A mutex can be initialized statically if its storage is zero-
filled. In this case, the mutex is of type USYNC_THREAD, and
mutex_init need not be called.
Return Values
mutex_init returns zero for success and an error number for
failure, as described below.
Copyright 1994 Novell, Inc. Page 1
mutex_init(3synch) mutex_init(3synch)
Errors
If any of the following conditions is detected, the contents
of mutex are unchanged and mutex_init returns the
corresponding value:
EINVAL Invalid type argument specified.
USAGE
Warnings
mutex_init does not examine the mutex argument before
initializing it. If mutex_init is called more than once for
the same mutex, it will overwrite its state. It is the user's
responsibility to ensure that mutex_init is only called once
for each mutex.
Operations on locks initialized with mutex_init are not
recursive-a thread can deadlock if it attempts to relock a
mutex that it already has locked.
REFERENCES
mutex(3synch), mutex_destroy(3synch), mutex_lock(3synch),
mutex_trylock(3synch), mutex_unlock(3synch), synch(3synch)
Copyright 1994 Novell, Inc. Page 2