mutex_init(3synch)


mutex_init -- initialize a mutex

Synopsis

   cc [options] -Kthread file
   

#include <synch.h>

int mutex_init(mutex_t *mutex, int type, void *arg);

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 reinitialized.

Parameters


mutex
pointer to mutex to be initialized

type
USYNC_THREAD or USYNC_PROCESS

arg
NULL (reserved for future use)

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.

Errors

If the following condition is detected, the contents of mutex are unchanged and mutex_init returns the corresponding value:

EINVAL
invalid type argument specified

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

Intro(3synch), mutex(3synch), mutex_destroy(3synch), mutex_lock(3synch), mutex_trylock(3synch), mutex_unlock(3synch)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004