summaryrefslogtreecommitdiffstats
path: root/upstream/debian-bookworm/man3/pthread_mutexattr_init.3
blob: eea58952e271897df419e6cea6055c6ef764265c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
.TH PTHREAD_MUTEXATTR 3 LinuxThreads


.SH NAME
pthread_mutexattr_init, pthread_mutexattr_destroy, pthread_mutexattr_settype, pthread_mutexattr_gettype \- mutex creation attributes

.SH SYNOPSIS
.B #include <pthread.h>

.BI "int pthread_mutexattr_init(pthread_mutexattr_t *" attr ");"

.BI "int pthread_mutexattr_destroy(pthread_mutexattr_t *" attr ");"

.BI "int pthread_mutexattr_settype(pthread_mutexattr_t *" attr ", int " kind ");"

.BI "int pthread_mutexattr_gettype(const pthread_mutexattr_t *" attr ", int *" kind ");"

.SH DESCRIPTION

Mutex attributes can be specified at mutex creation time, by passing a
mutex attribute object as second argument to \fBpthread_mutex_init\fP(3).
Passing \fBNULL\fP is equivalent to passing a mutex attribute object with
all attributes set to their default values.

\fBpthread_mutexattr_init\fP initializes the mutex attribute object \fIattr\fP
and fills it with default values for the attributes.

\fBpthread_mutexattr_destroy\fP destroys a mutex attribute object, which
must not be reused until it is reinitialized. \fBpthread_mutexattr_destroy\fP
does nothing in the LinuxThreads implementation. 

LinuxThreads supports only one mutex attribute: the mutex kind, which
is either \fBPTHREAD_MUTEX_FAST_NP\fP for ``fast'' mutexes,
\fBPTHREAD_MUTEX_RECURSIVE_NP\fP for ``recursive'' mutexes,
or \fBPTHREAD_MUTEX_ERRORCHECK_NP\fP for ``error checking'' mutexes.
As the \fBNP\fP suffix indicates, this is a non-portable extension to the
POSIX standard and should not be employed in portable programs.

The mutex kind determines what happens if a thread attempts to lock a
mutex it already owns with \fBpthread_mutex_lock\fP(3). If the mutex is of
the ``fast'' kind, \fBpthread_mutex_lock\fP(3) simply suspends the calling
thread forever.  If the mutex is of the ``error checking'' kind,
\fBpthread_mutex_lock\fP(3) returns immediately with the error code
\fBEDEADLK\fP.  If the mutex is of the ``recursive'' kind, the call to
\fBpthread_mutex_lock\fP(3) returns immediately with a success return
code. The number of times the thread owning the mutex has locked it is
recorded in the mutex. The owning thread must call
\fBpthread_mutex_unlock\fP(3) the same number of times before the mutex
returns to the unlocked state.

The default mutex kind is ``fast'', that is, \fBPTHREAD_MUTEX_FAST_NP\fP.

\fBpthread_mutexattr_settype\fP sets the mutex kind attribute in \fIattr\fP
to the value specified by \fIkind\fP.

\fBpthread_mutexattr_gettype\fP retrieves the current value of the
mutex kind attribute in \fIattr\fP and stores it in the location pointed
to by \fIkind\fP.

.SH "RETURN VALUE"
\fBpthread_mutexattr_init\fP, \fBpthread_mutexattr_destroy\fP and
\fBpthread_mutexattr_gettype\fP always return 0.

\fBpthread_mutexattr_settype\fP returns 0 on success and a non-zero
error code on error.

.SH ERRORS

On error, \fBpthread_mutexattr_settype\fP returns the following error code:
.TP
\fBEINVAL\fP
\fIkind\fP is neither \fBPTHREAD_MUTEX_FAST_NP\fP nor \fBPTHREAD_MUTEX_RECURSIVE_NP\fP
nor \fBPTHREAD_MUTEX_ERRORCHECK_NP\fP

.SH AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr>

.SH "SEE ALSO"
\fBpthread_mutex_init\fP(3),
\fBpthread_mutex_lock\fP(3),
\fBpthread_mutex_unlock\fP(3).