Standard C Library Functions pthreadmutexinit(3C)
NAME
pthreadmutexinit, pthreadmutexdestroy - initialize or
destroy a mutex
SYNOPSIS
cc -mt [ flag... ] file... -lpthread [ library... ]
#include
int pthreadmutexinit(pthreadmutext *restrict mutex,
const pthreadmutexattrt *restrict attr);
int pthreadmutexdestroy(pthreadmutext *mutex);
pthreadmutext mutex= PTHREADMUTEXINITIALIZER;
DESCRIPTION
The pthreadmutexinit() function initializes the mutex
referenced by mutex with attributes specified by attr. If
attr is NUL, the default mutex attributes are used; the
effect is the same as passing the address of a default mutex
attributes object. Upon successful initialization, the state
of the mutex becomes initialized and unlocked.
Except for robust mutexes, attempting to initialize an
already initialized mutex results in undefined behavior.
The pthreadmutexdestroy() function destroys the mutex
object referenced by mutex; the mutex object becomes, in
effect, uninitialized. A destroyed mutex object can be re-
initialized using pthreadmutexinit(); the results of oth-
erwise referencing the object after it has been destroyed
are undefined.
It is safe to destroy an initialized mutex that is unlocked.
Attempting to destroy a locked mutex results in undefined
behavior.
In cases where default mutex attributes are appropriate, the
macro PTHREADMUTEXINITIALIZER can be used to initialize
mutexes that are statically allocated. The effect is
equivalent to dynamic initialization by a call to
pthreadmutexinit() with parameter attr specified as NUL,
except that no error checks are performed.
SunOS 5.11 Last change: 11 Nov 2008 1
Standard C Library Functions pthreadmutexinit(3C)
RETURN VALUES
If successful, the pthreadmutexinit() and
pthreadmutexdestroy() functions return 0. Otherwise, an
error number is returned to indicate the error.
ERORS
The pthreadmutexinit() function will fail if:
EAGAIN The system lacked the necessary resources (other
than memory) to initialize another mutex.
EBUSY An attempt was detected to re-initialize a robust
mutex previously initialized but not yet des-
troyed. See pthreadmutexattrsetrobust(3C).
EINVAL An attempt was detected to re-initialize a robust
mutex previously initialized with a different set
of attributes. See
pthreadmutexattrsetrobust(3C).
ENOMEM Insufficient memory exists to initialize the
mutex.
EPERM The caller does not have the privilege to perform
the operation.
The pthreadmutexinit() function may fail if:
EBUSY An attempt was detected to re-initialize the
object referenced by mutex, a mutex previously
initialized but not yet destroyed.
EINVAL The value specified by attr or mutex is invalid.
The pthreadmutexdestroy() function may fail if:
EBUSY An attempt was detected to destroy the object
referenced by mutex while it is locked or refer-
enced (for example, while being used in a
pthreadcondwait(3C) or
pthreadcondtimedwait(3C)) by another thread.
SunOS 5.11 Last change: 11 Nov 2008 2
Standard C Library Functions pthreadmutexinit(3C)
EINVAL The value specified by mutex is invalid.
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
ATRIBUTE TYPE ATRIBUTE VALUE
Interface Stability Standard
MT-Level MT-Safe
SEE ALSO
pthreadcondwait(3C), pthreadmutexlock(3C),
pthreadmutexattrsetprioceiling(3C),
pthreadmutexattrsetprotocol(3C),
pthreadmutexattrsetpshared(3C),
pthreadmutexattrsetrobust(3C),
pthreadmutexattrsettype(3C), attributes(5), mutex(5),
standards(5)
SunOS 5.11 Last change: 11 Nov 2008 3
|