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
11

NAME

13       pthread_mutex_timedlock — lock a mutex
14

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

119       None.
120

APPLICATION USAGE

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

RATIONALE

132       Refer to pthread_mutex_lock().
133

FUTURE DIRECTIONS

135       None.
136

SEE ALSO

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