xref: /freebsd/share/man/man3/pthread_mutex_timedlock.3 (revision eba230afba4932f02a1ca44efc797cf7499a5cb0)
1.\" Copyright (c) 2003 Michael Telahun Makonnen
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd August 7, 2019
26.Dt PTHREAD_MUTEX_TIMEDLOCK 3
27.Os
28.Sh NAME
29.Nm pthread_mutex_timedlock
30.Nd lock a mutex without blocking indefinitely
31.Sh LIBRARY
32.Lb libpthread
33.Sh SYNOPSIS
34.In pthread.h
35.In time.h
36.Ft int
37.Fn pthread_mutex_timedlock "pthread_mutex_t *restrict mutex" "const struct timespec *restrict abs_timeout"
38.Sh DESCRIPTION
39The
40.Fn pthread_mutex_timedlock
41function will lock
42.Fa mutex .
43If it is already locked the calling thread will block until
44the mutex becomes available or
45the timeout,
46specified by abs_timeout,
47expires.
48The time of the timeout is an absolute time and
49is not relative to the current time.
50.Sh RETURN VALUES
51If successful,
52.Fn pthread_mutex_timedlock
53will return zero, otherwise an error number will be returned to
54indicate the error.
55.Sh ERRORS
56The
57.Fn pthread_mutex_timedlock
58function will fail if:
59.Bl -tag -width Er
60.It Bq "Er ENOTRECOVERABLE"
61The
62.Fa mutex
63was created with the protocol attribute having the
64value PTHREAD_PRIO_PROTECT and
65the calling thread's priority is higher than the
66mutex's current priority ceiling.
67.It Bq Er EINVAL
68The process or thread would have blocked, and
69.Fa abs_timeout
70specified a nanosecond value less than zero or
71greater than or equal to 1 billion.
72.It Bq Er EINVAL
73The
74.Fa mutex
75parameter is invalid.
76.It Bq Er ETIMEDOUT
77The
78.Fa mutex
79could not be locked before the timeout expired.
80.It Bq Er EAGAIN
81The
82.Fa mutex
83could not be acquired because the
84maximum number of recursive locks for the
85.Fa mutex
86has been exceeded.
87.It Bq Er EDEADLK
88The current thread already owns the
89.Fa mutex .
90.It Bq Er EOWNERDEAD
91The argument
92.Fa mutex
93points to a robust mutex and the process containing the previous owning
94thread terminated while holding the mutex lock.
95The lock was granted to the caller and it is up to the new owner
96to make the state consistent.
97.It Bq Er ENOTRECOVERABLE
98The state protected by the
99.Fa mutex
100is not recoverable.
101.El
102.Sh SEE ALSO
103.Xr pthread_mutex_consistent 3 ,
104.Xr pthread_mutex_destroy 3 ,
105.Xr pthread_mutex_init 3 ,
106.Xr pthread_mutex_lock 3 ,
107.Xr pthread_mutex_trylock 3 ,
108.Xr pthread_mutex_unlock 3
109.Sh STANDARDS
110The
111.Fn pthread_mutex_timedlock
112function is expected to conform to
113.St -p1003.1-96 .
114