1PTHREAD_MUTEXATTR_GETTYPE(3PP)OSIX Programmer's ManuPaTlHREAD_MUTEXATTR_GETTYPE(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       pthread_mutexattr_gettype, pthread_mutexattr_settype - get and set  the
13       mutex type attribute
14

SYNOPSIS

16       #include <pthread.h>
17
18       int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
19              int *restrict type);
20       int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);
21
22

DESCRIPTION

24       The  pthread_mutexattr_gettype()  and pthread_mutexattr_settype() func‐
25       tions, respectively, shall get and set the mutex type  attribute.  This
26       attribute  is set in the type parameter to these functions. The default
27       value of the type attribute is PTHREAD_MUTEX_DEFAULT.
28
29       The type of mutex is contained in  the  type  attribute  of  the  mutex
30       attributes. Valid mutex types include:
31
32       PTHREAD_MUTEX_NORMAL
33
34              This type of mutex does not detect deadlock. A thread attempting
35              to relock this mutex without first unlocking it shall  deadlock.
36              Attempting  to  unlock  a  mutex  locked  by  a different thread
37              results in undefined behavior. Attempting to unlock an  unlocked
38              mutex results in undefined behavior.
39
40       PTHREAD_MUTEX_ERRORCHECK
41
42              This  type of mutex provides error checking. A thread attempting
43              to relock this mutex without first  unlocking  it  shall  return
44              with  an  error.  A  thread  attempting  to unlock a mutex which
45              another thread has locked shall return with an error.  A  thread
46              attempting  to  unlock  an  unlocked  mutex shall return with an
47              error.
48
49       PTHREAD_MUTEX_RECURSIVE
50
51              A thread attempting to relock this mutex without first unlocking
52              it  shall  succeed  in locking the mutex. The relocking deadlock
53              which can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot
54              occur  with  this  type  of  mutex. Multiple locks of this mutex
55              shall require the same number of unlocks to  release  the  mutex
56              before another thread can acquire the mutex. A thread attempting
57              to unlock a mutex which another thread has locked  shall  return
58              with  an error.  A thread attempting to unlock an unlocked mutex
59              shall return with an error.
60
61       PTHREAD_MUTEX_DEFAULT
62
63              Attempting to recursively lock a mutex of this type  results  in
64              undefined  behavior.  Attempting  to unlock a mutex of this type
65              which was not locked by the calling thread results in  undefined
66              behavior.   Attempting  to  unlock a mutex of this type which is
67              not locked results in undefined behavior. An implementation  may
68              map this mutex to one of the other mutex types.
69
70

RETURN VALUE

72       Upon  successful  completion,  the pthread_mutexattr_gettype() function
73       shall return zero and store the value of the  type  attribute  of  attr
74       into  the  object referenced by the type parameter. Otherwise, an error
75       shall be returned to indicate the error.
76
77       If successful, the pthread_mutexattr_settype()  function  shall  return
78       zero;  otherwise,  an  error  number  shall be returned to indicate the
79       error.
80

ERRORS

82       The pthread_mutexattr_settype() function shall fail if:
83
84       EINVAL The value type is invalid.
85
86
87       The pthread_mutexattr_gettype() and  pthread_mutexattr_settype()  func‐
88       tions may fail if:
89
90       EINVAL The value specified by attr is invalid.
91
92
93       These functions shall not return an error code of [EINTR].
94
95       The following sections are informative.
96

EXAMPLES

98       None.
99

APPLICATION USAGE

101       It is advised that an application should not use a PTHREAD_MUTEX_RECUR‐
102       SIVE mutex with condition variables because the  implicit  unlock  per‐
103       formed  for  a  pthread_cond_timedwait() or pthread_cond_wait() may not
104       actually release the mutex (if it had been locked multiple  times).  If
105       this  happens,  no other thread can satisfy the condition of the predi‐
106       cate.
107

RATIONALE

109       None.
110

FUTURE DIRECTIONS

112       None.
113

SEE ALSO

115       pthread_cond_timedwait(),    the    Base    Definitions    volume    of
116       IEEE Std 1003.1-2001, <pthread.h>
117
119       Portions  of  this text are reprinted and reproduced in electronic form
120       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
121       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
122       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
123       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
124       event of any discrepancy between this version and the original IEEE and
125       The  Open Group Standard, the original IEEE and The Open Group Standard
126       is the referee document. The original Standard can be  obtained  online
127       at http://www.opengroup.org/unix/online.html .
128
129
130
131IEEE/The Open Group                  2003        PTHREAD_MUTEXATTR_GETTYPE(3P)
Impressum