1PTHREAD_MUTEX_TIMEDLOCK(3P)POSIX Programmer's ManualPTHREAD_MUTEX_TIMEDLOCK(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_mutex_timedlock — lock a mutex
13

SYNOPSIS

15       #include <pthread.h>
16       #include <time.h>
17
18       int pthread_mutex_timedlock(pthread_mutex_t *restrict mutex,
19           const struct timespec *restrict abstime);
20

DESCRIPTION

22       The pthread_mutex_timedlock() function shall lock the mutex object ref‐
23       erenced  by  mutex.  If the mutex is already locked, the calling thread
24       shall  block  until   the   mutex   becomes   available   as   in   the
25       pthread_mutex_lock()  function.  If  the mutex cannot be locked without
26       waiting for another thread to unlock the mutex, this wait shall be ter‐
27       minated when the specified timeout expires.
28
29       The  timeout  shall  expire when the absolute time specified by abstime
30       passes, as measured by the clock on which timeouts are based (that  is,
31       when  the  value  of  that  clock equals or exceeds abstime), or if the
32       absolute time specified by abstime has already been passed at the  time
33       of the call.
34
35       The timeout shall be based on the CLOCK_REALTIME clock.  The resolution
36       of the timeout shall be the resolution of the  clock  on  which  it  is
37       based. The timespec data type is defined in the <time.h> header.
38
39       Under  no  circumstance  shall  the function fail with a timeout if the
40       mutex can be locked immediately. The validity of the abstime  parameter
41       need not be checked if the mutex can be locked immediately.
42
43       As  a  consequence  of the priority inheritance rules (for mutexes ini‐
44       tialized with the PRIO_INHERIT protocol), if a timed mutex wait is ter‐
45       minated  because  its timeout expires, the priority of the owner of the
46       mutex shall be adjusted as necessary to  reflect  the  fact  that  this
47       thread is no longer among the threads waiting for the mutex.
48
49       If mutex is a robust mutex and the process containing the owning thread
50       terminated while holding the mutex lock, a call to pthread_mutex_timed‐
51       lock() shall return the error value [EOWNERDEAD].  If mutex is a robust
52       mutex and the owning thread terminated while holding the mutex lock,  a
53       call  to  pthread_mutex_timedlock()  may  return the error value [EOWN‐
54       ERDEAD] even if the process in which the owning thread resides has  not
55       terminated.  In  these cases, the mutex is locked by the thread but the
56       state it protects is marked as  inconsistent.  The  application  should
57       ensure  that  the  state  is made consistent for reuse and when that is
58       complete call pthread_mutex_consistent().  If the application is unable
59       to  recover  the state, it should unlock the mutex without a prior call
60       to pthread_mutex_consistent(), after which the mutex is  marked  perma‐
61       nently unusable.
62
63       If mutex does not refer to an initialized mutex object, the behavior is
64       undefined.
65

RETURN VALUE

67       If successful,  the  pthread_mutex_timedlock()  function  shall  return
68       zero;  otherwise,  an  error  number  shall be returned to indicate the
69       error.
70

ERRORS

72       The pthread_mutex_timedlock() function shall fail if:
73
74       EAGAIN The mutex could not be acquired because the  maximum  number  of
75              recursive locks for mutex has been exceeded.
76
77       EDEADLK
78              The  mutex  type  is  PTHREAD_MUTEX_ERRORCHECK  and  the current
79              thread already owns the mutex.
80
81       EINVAL The mutex was created with the  protocol  attribute  having  the
82              value  PTHREAD_PRIO_PROTECT and the calling thread's priority is
83              higher than the mutex' current priority ceiling.
84
85       EINVAL The process or thread would have blocked, and the abstime param‐
86              eter  specified  a  nanoseconds  field  value  less than zero or
87              greater than or equal to 1000 million.
88
89       ENOTRECOVERABLE
90              The state protected by the mutex is not recoverable.
91
92       EOWNERDEAD
93              The mutex is a robust mutex and the process containing the  pre‐
94              vious owning thread terminated while holding the mutex lock. The
95              mutex lock shall be acquired by the calling thread and it is  up
96              to the new owner to make the state consistent.
97
98       ETIMEDOUT
99              The  mutex  could  not  be  locked  before the specified timeout
100              expired.
101
102       The pthread_mutex_timedlock() function may fail if:
103
104       EDEADLK
105              A deadlock condition was detected.
106
107       EOWNERDEAD
108              The mutex is a robust mutex and the previous owning thread  ter‐
109              minated  while  holding  the mutex lock. The mutex lock shall be
110              acquired by the calling thread and it is up to the new owner  to
111              make the state consistent.
112
113       This function shall not return an error code of [EINTR].
114
115       The following sections are informative.
116

EXAMPLES

118       None.
119

APPLICATION USAGE

121       Applications  that  have assumed that non-zero return values are errors
122       will need updating for use with robust mutexes, since  a  valid  return
123       for  a  thread acquiring a mutex which is protecting a currently incon‐
124       sistent state is [EOWNERDEAD].  Applications  that  do  not  check  the
125       error  returns,  due to ruling out the possibility of such errors aris‐
126       ing, should not use robust mutexes. If an application  is  supposed  to
127       work  with normal and robust mutexes, it should check all return values
128       for error conditions and if necessary take appropriate action.
129

RATIONALE

131       Refer to pthread_mutex_lock().
132

FUTURE DIRECTIONS

134       None.
135

SEE ALSO

137       pthread_mutex_destroy(), pthread_mutex_lock(), time()
138
139       The Base Definitions volume of POSIX.1‐2017, Section 4.12, Memory  Syn‐
140       chronization, <pthread.h>, <time.h>
141
143       Portions  of  this text are reprinted and reproduced in electronic form
144       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
145       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
146       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
147       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
148       event of any discrepancy between this version and the original IEEE and
149       The  Open Group Standard, the original IEEE and The Open Group Standard
150       is the referee document. The original Standard can be  obtained  online
151       at http://www.opengroup.org/unix/online.html .
152
153       Any  typographical  or  formatting  errors that appear in this page are
154       most likely to have been introduced during the conversion of the source
155       files  to  man page format. To report such errors, see https://www.ker
156       nel.org/doc/man-pages/reporting_bugs.html .
157
158
159
160IEEE/The Open Group                  2017          PTHREAD_MUTEX_TIMEDLOCK(3P)
Impressum