pthread_mutexattr_setkind_np(3-thr) pthread_mutexattr_setkind_np(3-thr)
NAME
pthreadmutexattrsetkindnp - specifies the mutex type attribute
SYNOPSIS
#include <pthread.h>
int pthreadmutexattrsetkindnp(
pthreadmutexattrt *attr,
int kind);
PARAMETERS
attr Mutex attributes object modified.
kind New value for the mutex type attribute. The kind parameter
specifies the type of mutex that is created. Valid values
are MUTEXFASTNP (default), MUTEXRECURSIVENP, and
MUTEXNONRECURSIVENP.
DESCRIPTION
The pthreadmutexattrsetkindnp() routine sets the mutex type attri-
bute that is used when a mutex is created.
A fast mutex is locked and unlocked in the fastest manner possible. A
fast mutex can only be locked (obtained) once. All subsequent calls to
pthreadmutexlock() cause the calling thread to block until the mutex
is freed by the thread that owns it. If the thread that owns the mutex
attempts to lock it again, the thread waits for itself to release the
mutex (causing a deadlock).
A recursive mutex can be locked more than once by the same thread
without causing that thread to deadlock. In other words, a single
thread can make consecutive calls to pthreadmutexlock() without
blocking. The thread must then call pthreadmutexunlock() the same
number of times as it called pthreadmutexlock() before another
thread can lock the mutex.
A nonrecursive mutex is locked only once by a thread, like a fast
mutex. If the thread tries to lock the mutex again without first
unlocking it, the thread receives an error. Thus, nonrecursive mutexes
are more informative than fast mutexes because fast mutexes block in
such a case, leaving it up to you to determine why the thread no
longer executes. Also, if someone other than the owner tries to unlock
a nonrecursive mutex, an error is returned.
Never use a recursive mutex with condition variables because the
implicit unlock performed for a pthreadcondwait() or
pthreadcondtimedwait() might not actually release the mutex. In that
case, no other thread can satisfy the condition of the predicate.
This routine is a new primitive.
Page 1 Reliant UNIX 5.44 Printed 11/98
pthread_mutexattr_setkind_np(3-thr) pthread_mutexattr_setkind_np(3-thr)
RETURN VALUES
If the function fails, errno may be set to one of the following
values:
EINVAL The value specified by attr is invalid.
EPERM The caller does not have the appropriate privileges.
ERANGE One or more parameters supplied have an invalid value.
SEE ALSO
pthreadmutexinit(3-thr), pthreadmutexattrcreate(3-thr),
pthreadmutexattrgetkindnp(3-thr).
Page 2 Reliant UNIX 5.44 Printed 11/98